128 次阅读

Rust学习: wait [标准库]

如果你想等待 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
reached end of main
# `wait` keeps running for 5 seconds
# `sleep 5` command ends, and then our `wait` program finishes

相关文章

此处评论已关闭

© 2019 MBIOQ Crafted with Typecho. Theme by Junichi
If you find anything I made helpful,I’d love to hear from you!