[英]How can I convert a std::process::Command into a command line string?
For example: 例如:
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();
This will spawn a process with this command line "ProgramA" -a foo -b "--argument=with space"
associated with it. 这将产生与此命令行
"ProgramA" -a foo -b "--argument=with space"
关联的"ProgramA" -a foo -b "--argument=with space"
。
Is there a way to get this back out from the com
object? 有没有办法从
com
对象中恢复过来?
It turns out Command
implements Debug
; 事实证明
Command
实现了Debug
; this will give me the desired result: 这将给我想要的结果:
let answer = format!("{:?}", com);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.