等待 - 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::Child` 完成，你必须调用 `Child::wait`，它会返回一个 `process::ExitStatus`。

    use std::process::Command;

    fn main() {
        let mut child = Command::new("sleep").arg("5").spawn().unwrap();
        let _result = child.wait().unwrap();

        println!("到达 main 函数末尾");
    }

    $ rustc wait.rs && ./wait
    # `wait` 会持续运行 5 秒，直到 `sleep 5` 命令执行完毕
    reached end of main