Remove a lot of clutter and boilerplate when using std::process::Command
.
Macros
Use the cmd!
macro to create plain std::process:Command
structs, use exec!
and run!
to execute them directly via status()
and output()
respectively
run!;
# equivalent to
new.arg.output;
All arguments will be treated as whitespace separated strings by default. If your argument includes whitespace, wrap it in quotes as shown above.
To use an existing variable as an arg, wrap its name in braces. You can mix arguments of different types (unlike the .args()
method).
run!;
# equivalent to
new.arg.arg.arg.output;
If your variable is iterable you can expand it using ..
run!
If your argument is optional you can use ?
to only append it if it is Some
let name = Some;
run!;
If you include a literal inside the same braces the literal will also only be included if the value is Some
(use this for flags).
This also works for iterables.
let packages = vec!;
run!;
Use the args!
macro to append arguments to an exist Command
using the same syntax as cmd!
Extensions
Use the cmd_ok()
method on the return value of status()
or output()
to create an Err()
on both IO failure and any exit code except 0
, the latter will include the contents of stderr if they are available.
run!.cmd_ok?
Use opt_arg
to pass optional values to your Command and only use them if they are Some
.
Use output.stdout()
, output.stderr()
, output.stdout_lossy()
and output.stderr_lossy()
instead of String::from_utf8(output.stdout)
.