Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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

like image 386
8176135 Avatar asked Sep 07 '25 11:09

8176135


1 Answers

It turns out Command implements Debug; this will give me the desired result:

let answer = format!("{:?}", com);
like image 55
8176135 Avatar answered Sep 09 '25 19:09

8176135