如何将std :: process :: Command转换为命令行字符串? [英] How can I convert a std::process::Command into a command line string?

查看:256
本文介绍了如何将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 与之关联。

This will spawn a process with this command line "ProgramA" -a foo -b "--argument=with space" associated with it.

是否有办法将其从<$ c中删除$ c> com 对象?

Is there a way to get this back out from the com object?

推荐答案

原来是 Command 实现 Debug ;

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

这篇关于如何将std :: process :: Command转换为命令行字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆