问题
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.
Is there a way to get this back out from the com
object?
回答1:
It turns out Command
implements Debug
; this will give me the desired result:
let answer = format!("{:?}", com);
来源:https://stackoverflow.com/questions/53716197/how-can-i-convert-a-stdprocesscommand-into-a-command-line-string