简体   繁体   English

如何将std :: process :: Command转换为命令行字符串?

[英]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.

相关问题 如何从 Ubuntu 上的 PowerShell Core 获取进程命令行? - How can I get process command line from PowerShell Core on Ubuntu? 在执行快照的快照之后,如何获取所有进程的完整命令行? - How can I get the full command line of all the processes after doing a process walk of the snapshot? 如何在linux命令行中查看进程的命令行和环境变量 - How to view the command line and environment variables for a process in the linux command line 与命令行过程进行交互 - Interacting with a command line process 命令行过程 - Command Line Process 如何使用带有多个括号的Process.Start()命令? - How can I use the Process.Start() command with multiple parenthesis? 如何通过PID向CMD进程发送关闭命令 - How can i send close command to a CMD process by PID 仅当进程来自当前用户时,才如何查找进程的命令行 - How to find the command line of a process only if the process is from current user 是否有比`std :: process :: Command`更低级别的接口来将单个字符串作为进程执行? - Is there a lower level interface than `std::process::Command` to execute a single string as a process? 从win7的命令行,如何以管理员身份启动具有升高的UAC的进程 - From command line on win7, how do I launch a process as administrator with elevated UAC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM