Though cmd_lib can pass a vector to run_cmd!, the vector item must still be the same type, which is inconvenient.
For example, trying to pass arguments wich contains both literal &str and integer u64 needs to be like:
let a = 999999u32;
let b = 88888u64;
let args = vec!("-a".to_string(), a.to_string(), "-b".to_string(), b.to_string());
run_cmd!(some_cmd $[args]);
all items must be converted to String. Using Command can be more easy:
let mut cmd = Command::new(some_cmd);
cmd.arg("-a").arg(a.to_string());
cmd.arg("-b").arg(b.to_string());
let output = cmd.output();
this example can easily construct the command and corresponding arguments, but it is hard to control the subprocess, while cmd_lib is easy to run the command but hard to construct it.
I'm wondering, how can I use Command to construct commands and use cmd_lib to launch the command?
If the answer is no, when cmd_lib can cooperate with Command, would it be better for both command construction and controlling?
I am not very familiar with Rust.
Though cmd_lib can pass a vector to
run_cmd!
, the vector item must still be the same type, which is inconvenient.For example, trying to pass arguments wich contains both literal
&str
and integeru64
needs to be like:all items must be converted to
String
. Using Command can be more easy:this example can easily construct the command and corresponding arguments, but it is hard to control the subprocess, while cmd_lib is easy to run the command but hard to construct it.
I'm wondering, how can I use Command to construct commands and use cmd_lib to launch the command? If the answer is no, when cmd_lib can cooperate with Command, would it be better for both command construction and controlling?