Macro embuild::cmd_output[][src]

macro_rules! cmd_output {
    ($cmd : expr $(, $(@ $cmdargs : expr,) * $cmdarg : expr) * ; ignore_exitcode
 $(, $k : ident = $v : tt) *) => { ... };
    ($cmd : expr $(, $(@ $cmdargs : expr,) * $cmdarg : expr) *
 $(; $($k : ident = $v : tt), *) ?) => { ... };
}
Expand description

Run a command to completion and gets its stdout output.

This is a simple wrapper over the std::process::Command API. It expects at least one argument for the program to run. Every comma seperated argument thereafter is added to the command’s arguments. Arguments after an @-sign specify collections of arguments (specifically impl IntoIterator<Item = impl AsRef<OsStr>). The opional key=value arguments after a semicolon are simply translated to calling the std::process::Command::<key> method with value as its arguments.

Note: @-arguments must be followed by at least one normal argument. For example cmd!("cmd", @args) will not compile but cmd!("cmd", @args, "other") will. You can use key=value arguments to work around this limitation: cmd!("cmd"; args=(args)).

After building the command std::process::Command::output is called. If the command succeeded its stdout output is returned as a String otherwise an error is returned. If ignore_exitcode is specified as the first key=value argument, the command’s output will be returned even if it ran unsuccessfully.

Examples

let args_list = ["--foo", "--bar", "value"];
cmd_output!("git", @args_list, "clone"; arg=("url.com"), env=("var", "value"));