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!("reached end of main");
}
$ rustc wait.rs && ./wait
# `wait` は `sleep 5` コマンドが終了するまで 5 秒間実行され続ける
reached end of main