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.
Simply include the library and invoke the run function with the script text and run options:
````rust extern crate run_script;
use run_script::ScriptOptions;
fn main() { let mut options = ScriptOptions::new(); options.runner = None; // The script runner, for example bash. By default for windows it's cmd.exe and for other systems it is sh. options.captureoutput = true; // True to capture and return the output. False will print it to the parent process output. options.exitonerror = false; // Adds set -e option (not available for windows) options.printcommands = false; // Adds set -x option (not available for windows)
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);
} ````
In order to use this library, just add it as a dependency:
ini
[dependencies]
run_script = "*"
See full docs at: API Docs
| Date | Version | Description | | ----------- | ------- | ----------- | | 2017-12-14 | v0.1.7 | Maintenance | | 2017-11-04 | v0.1.1 | Initial release. |
Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.