Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

자식 프로세스

process::Output 구조체는 종료된 자식 프로세스의 출력을 나타내며, process::Command 구조체는 프로세스 빌더입니다.

use std::process::Command;

fn main() {
    let output = Command::new("rustc")
        .arg("--version")
        .output().unwrap_or_else(|e| {
            panic!("프로세스 실행 실패: {}", e)
    });

    if output.status.success() {
        let s = String::from_utf8_lossy(&output.stdout);

        print!("rustc가 성공했으며 표준 출력은 다음과 같습니다:\n{}", s);
    } else {
        let s = String::from_utf8_lossy(&output.stderr);

        print!("rustc가 실패했으며 표준 에러는 다음과 같습니다:\n{}", s);
    }
}

(이전 예제에서 rustc에 잘못된 플래그를 전달하여 시도해 보시길 권장합니다.)