pub trait CommandExecute {
// Required methods
fn execute(self, output: Output) -> Result<Vec<u8>>;
fn run(self) -> Result<()>;
// Provided method
fn execute_str(self, output: Output) -> Result<String>
where Self: CommandString + Sized { ... }
}
Expand description
Execute a command.
This trait is intended to endow Command
with execute
and execute_str
, handling the
output of execution for easy use. See the
implementation on Command
for more details.
Required Methods§
Provided Methods§
Sourcefn execute_str(self, output: Output) -> Result<String>where
Self: CommandString + Sized,
fn execute_str(self, output: Output) -> Result<String>where
Self: CommandString + Sized,
Execute and collect output into string.
Implementations on Foreign Types§
Source§impl CommandExecute for Command
impl CommandExecute for Command
Run a Command
to completion and handle the output.
Execution provides a simple way to run a command to completion and capture the outputs.
Both stdout and stderr are captured, the output
argument describes how they should be
directed to the parent stdio.
By default, output is Output::Verbose
which prints both the stdout and stderr to the terminal.
The result of the execution is the raw stdout bytes. Use execute_str
to try to encode this
into a String
.
If the command exits with an error (ie ExitStatus::success
is false
), an error is
constructed which includes the captured stderr.
let ls = cmd!(ls).execute_str(Verbose).unwrap();
assert_eq!(&ls, "Cargo.lock
Cargo.toml
LICENSE
local.rs
README.md
src
target
template.rs
");