rust_script_ext::prelude

Trait CommandExecute

Source
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§

Source

fn execute(self, output: Output) -> Result<Vec<u8>>

Execute and collect output into a byte buffer.

Source

fn run(self) -> Result<()>

Run the command with no capturing IO.

Provided Methods§

Source

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

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
");
Source§

fn run(self) -> Result<()>

Run a command but do not capture IO.

This provides an error message displaying the command run.

Use this method when the command being run uses stdio for progress bars/updates.

Source§

fn execute(self, output: Output) -> Result<Vec<u8>>

Implementors§