dropの延期

process::Childが終了するのを待ちたい場合は、 process::ExitStatusを返すChild::waitを呼び出さなくてはなりません。

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` keeps running for 5 seconds until the `sleep 5` command finishes # `wait`は`sleep 5`コマンドが終了するまで5秒間実行され続ける。 reached end of main