Execute
This library is for extending Command
in order to execute programs more easily.
Usage
extern crate execute;
use Command;
use Execute;
// ...
Verify the Program
Since Command
is used for spawning a process of a command and the executed progrom is external which may not exist or may not be the program that we expected, we usually need to verify the external program at runtime.
The execute_check_exit_status_code
method can be used to execute a command and check its exit status. For example,
extern crate execute;
use Command;
use Execute;
const FFMPEG_PATH: &str = "/path/to/ffmpeg";
let mut first_command = new;
first_command.arg;
if first_command.execute_check_exit_status_code.is_err
Execute and Get the Exit Status
extern crate execute;
use Command;
use Execute;
const FFMPEG_PATH: &str = "/path/to/ffmpeg";
let mut command = new;
command.arg;
command.arg;
command.arg;
if let Some = command.execute.unwrap else
Execute and Get the Output
Output to the Screen
extern crate execute;
use Command;
use Execute;
const FFMPEG_PATH: &str = "/path/to/ffmpeg";
let mut command = new;
command.arg;
command.arg;
command.arg;
let output = command.execute_output.unwrap;
if let Some = output.status.code else
Output to Memory (Captured)
extern crate execute;
use ;
use Execute;
const FFMPEG_PATH: &str = "/path/to/ffmpeg";
let mut command = new;
command.arg;
command.arg;
command.arg;
command.stdout;
command.stderr;
let output = command.execute_output.unwrap;
if let Some = output.status.code else
println!;
println!;
Execute and Input Data
Input In-memory Data
extern crate execute;
use ;
use Execute;
let mut bc_command = new;
bc_command.stdout;
let output = bc_command.execute_input_output.unwrap;
println!;
Input from a Reader
extern crate execute;
use ;
use File;
use Execute;
let mut cat_command = new;
cat_command.stdout;
let mut file = open.unwrap;
let output = cat_command.execute_input_reader_output.unwrap;
println!;
By default, the buffer size is 256 bytes. If you want to change that, you can use the _reader_output2
or _reader2
methods and define a length explicitly.
For example, to change the buffer size to 4096 bytes,
extern crate execute;
use ;
use File;
use U4096;
use Execute;
# if cfg!
Execute Many Commands and Pipe Them Together
extern crate execute;
use ;
use Execute;
let mut command1 = new;
command1.arg;
let mut command2 = new;
command2.arg.arg.arg.arg;
let mut command3 = new;
command3.arg.arg;
command3.stdout;
let output = command1.execute_many_output.unwrap;
assert_eq!;
Crates.io
https://crates.io/crates/execute