Crate commandext [−] [src]
Defines the CommandExt
type.
CommandExt
wraps Command
and enhances it.
A CommandExt
is built similar to a Command
. Supply the command name, add
args, set enviroment variables, etc. The exec
function takes a closure
that executes the command and returns the given result T
.
Examples
use commandext::{CommandExt,to_procout}; let mut cmd = CommandExt::new("echo"); cmd.env("DEBUG", "true"); cmd.arg("test"); let output = cmd.exec(to_procout());
// Execute "echo 'Testing Spawn'" via spawn and verify the exit code was 0. // As a side effect, you would see 'Testing Spawn' on stdout. use commandext::{CommandExt,to_res}; let res = CommandExt::new("echo").arg("Testing Spawn").exec(to_res()); assert_eq!(Ok(0), res);
// Exeute "echo test" via output and verify the output is indeed "test\n". // In this case there is nothing on stdout. The output is consumed here. extern crate sodium_sys; extern crate commandext; use commandext::{CommandExt,to_procout}; use sodium_sys::crypto::utils::secmem; fn main() { let cmd = CommandExt::new("echo").arg("test").exec(to_procout()); let output = cmd.unwrap(); assert_eq!(secmem::memcmp(&[116, 101, 115, 116, 10], &output.stdout[..]), 0); }
Structs
CommandExt |
Extends |
Functions
header |
Surround a message with 80 # character lines. |
to_proc |
Generate a closure that returns a Child from the given command. |
to_procout |
Generate a closure that returns a Output from the given command. |
to_res |
Generate a closure that returns a Result with the exit code of the process. |