Wait

If you’d like to wait for a process::Child to finish, you must call
Child::wait, which will return a process::ExitStatus.

  1. use std::process::Command;
  2. fn main() {
  3. let mut child = Command::new("sleep").arg("5").spawn().unwrap();
  4. let _result = child.wait().unwrap();
  5. println!("reached end of main");
  6. }
  1. $ rustc wait.rs && ./wait
  2. reached end of main
  3. # `wait` keeps running for 5 seconds
  4. # `sleep 5` command ends, and then our `wait` program finishes