Working on my first rust app, and it issues a number of commands via std::process::Command. If one of these is incorrect I'd like to see what it is, and to have it look pretty on the command line.
Currently I have code that looks like this (simplified):
let mut command = std::process::Command::new("ls");
command.arg("-la");
println!("{:?}", command)
This is alright, but it encloses everything in quotes when it prints the string. The output looks like: "ls" "-la".
How can I format this so that it doesn't enclose each arg in double quotes, but instead produces a command that is easy to read? Something like: ls -la.
I saw a related issue, but it comes to the same mediocre solution.
Command adds the quotes because, while they're "ugly," they never break a command. On the other hand, not having them can! Parsing whether you need them or not, including all edge cases, can get surprisingly complicated.
If you have a tightly controlled set of use cases, and you are certain that you don't need them, then just remove them:
let mut command = std::process::Command::new("ls");
command.arg("-la");
println!("{}", format!("{:?}", command).replace("\"", ""));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With