18.5 Child processes

process::Output 구조체는 종료된 하위 프로세스의 출력을 나타내고, process::Command 구조체는 process 제작자다.

use std::process::Command;

fn main() {
    let output = Command::new("rustc")
        .arg("--version")
        .output().unwrap_or_else(|e| {
            panic!("failed to execute process: {}", e)
    });

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

        print!("rustc succeeded and stdout was:\n{}", s);
    } else {
        let s = String::from_utf8_lossy(&output.stderr);

        print!("rustc failed and stderr was:\n{}", s);
    }
}

(상기 예제에서 rustc에게 틀린 플래그를 전달해보세요.)

results matching ""

    No results matching ""