首页 > 解决方案 > 如何将 std::process::Command 转换为命令行字符串?

问题描述

例如:

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物体中取出来?

标签: processrustcommand

解决方案


原来是Command工具Debug;这会给我想要的结果:

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

推荐阅读