https://rust.ffactory.org/std/process/struct.Command.html
进程生成器,提供对如何生成新进程的细粒度控制。
可以使用 Command::new(program) 生成默认配置,其中 program 提供了要执行的程序的路径。
其他生成器方法允许在生成之前更改配置 (例如,通过添加参数) :
main.rs
use std::process::Command;
fn main() {
let output = if cfg!(target_os = "windows") {
Command::new("cmd")
.arg("/C")
.arg("calc")
.output()
.expect("failed to execute process")
} else {
Command::new("sh")
.arg("-c")
.arg("echo hello")
.output()
.expect("failed to execute process")
};
let hello = output.stdout;
println!("{:?}", hello)
}
标签:process,arg,new,实例,Command,计算器,output,hello,rust
From: https://www.cnblogs.com/Nazorine/p/16705634.html