Crate run_script
source ·Expand description
run_script
Run shell scripts in rust.
This library enables to invoke shell scripts based on their content.
While std::process::Command works great to execute standalone command, you need more manual code to take a script
text and execute it.
For this purpose, this library was created.
Examples
Basic Example
extern crate run_script;
use run_script::ScriptOptions;
fn main() {
let options = ScriptOptions::new();
let args = vec![];
let (code, output, error) = run_script::run(
r#"
echo "Directory Info:"
dir
"#,
&args,
&options
).unwrap();
println!("Exit Code: {}", code);
println!("Output: {}", output);
println!("Error: {}", error);
}
Macro Examples
#[macro_use]
extern crate run_script;
use run_script::ScriptOptions;
fn main() {
// simple call to run script with only the script text
let (code, output, error) = run_script!(
r#"
echo "Test"
exit 0
"#
).unwrap();
// run script invoked with the script text and options
let options = ScriptOptions::new();
let (code, output, error) = run_script!(
r#"
echo "Test"
exit 0
"#,
&options
).unwrap();
// run script invoked with all arguments
let options = ScriptOptions::new();
let (code, output, error) = run_script!(
r#"
echo "Test"
exit 0
"#,
&vec!["ARG1".to_string(), "ARG2".to_string()],
&options
).unwrap();
}
Installation
In order to use this library, just add it as a dependency:
[dependencies]
run_script = "*"
Contributing
License
Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.
Modules
types
Macros
Enables to invoke the run_script::run function more easily without providing all input.
Functions
Invokes the provided script content and returns the invocation output.
Type Definitions
Error struct
Options available for invoking the script