How can I convert a std::process::Command into a command line string?

心不动则不痛 提交于 2020-06-16 04:33:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!