如何将一个 std::process::Command 转换成命令行字符串?

3

例如:

let mut com = std::process::Command::new("ProgramA");

com.env("ENV_1", "VALUE_1")
    .arg("-a")
    .arg("foo")
    .arg("-b")
    .arg("--argument=bar");

// Get the command line string somehow here.

com.output().unwrap();

这将使用以下命令行启动一个进程:"ProgramA" -a foo -b "--argument=with space"

是否有一种方法可以从com对象中提取它?

1个回答

3

原来Command实现了Debug接口;这将会给我想要的结果:

let answer = format!("{:?}", com);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接