子进程 - Rust By Example
Description: Rust by Example (RBE) is a collection of runnable examples that illustrate various Rust concepts and standard libraries.

## 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` 传递一个错误的标志）