Rust by Example

43.2 Wait

When a Process goes out of scope, its drop method will wait until the child process finishes before releasing the resource.


use std::old_io::process::Command;

fn main() {
    let _process = Command::new("sleep").arg("5").spawn();

    println!("reached end of main");
$ rustc && ./wait
reached end of main
# `wait` keeps running for 5 seconds
# `sleep 5` command ends, and then our `wait` program finishes