Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sagiegurari/run_script
Run shell scripts in rust.
https://github.com/sagiegurari/run_script
bash-script rust rust-library scripting shell-script
Last synced: 29 days ago
JSON representation
Run shell scripts in rust.
- Host: GitHub
- URL: https://github.com/sagiegurari/run_script
- Owner: sagiegurari
- License: apache-2.0
- Created: 2017-11-03T13:33:31.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-29T12:54:15.000Z (4 months ago)
- Last Synced: 2024-10-02T04:01:27.860Z (about 1 month ago)
- Topics: bash-script, rust, rust-library, scripting, shell-script
- Language: Rust
- Size: 4.05 MB
- Stars: 120
- Watchers: 4
- Forks: 13
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# run_script
[![crates.io](https://img.shields.io/crates/v/run_script.svg)](https://crates.io/crates/run_script) [![CI](https://github.com/sagiegurari/run_script/workflows/CI/badge.svg?branch=master)](https://github.com/sagiegurari/run_script/actions) [![codecov](https://codecov.io/gh/sagiegurari/run_script/branch/master/graph/badge.svg)](https://codecov.io/gh/sagiegurari/run_script)
[![license](https://img.shields.io/crates/l/run_script.svg)](https://github.com/sagiegurari/run_script/blob/master/LICENSE) [![Libraries.io for GitHub](https://img.shields.io/librariesio/github/sagiegurari/run_script.svg)](https://libraries.io/cargo/run_script) [![Documentation](https://docs.rs/run_script/badge.svg)](https://docs.rs/crate/run_script/) [![downloads](https://img.shields.io/crates/d/run_script.svg)](https://crates.io/crates/run_script)
[![Built with cargo-make](https://sagiegurari.github.io/cargo-make/assets/badges/cargo-make.svg)](https://sagiegurari.github.io/cargo-make)> Run shell scripts in [rust](https://www.rust-lang.org/).
* [Overview](#overview)
* [Usage](#usage)
* [Installation](#installation)
* [API Documentation](https://sagiegurari.github.io/run_script/)
* [Contributing](.github/CONTRIBUTING.md)
* [Release History](CHANGELOG.md)
* [License](#license)
## Overview
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.
## Usage
Simply include the library and invoke the run/spawn function with the script text and run options:```rust
use run_script::ScriptOptions;fn main() {
let options = ScriptOptions::new();let args = vec![];
// run the script and get the script execution output
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);// run the script and get a handle to the running child process
let child = run_script::spawn(
r#"
echo "Directory Info:"
dir
"#,
&args,
&options,
)
.unwrap();let spawn_output = child.wait_with_output().unwrap();
println!("Success: {}", &spawn_output.status.success());
}
```The library also provides the **run_script!**, **spawn_script!** and **run_script_or_exit!** macros for simpler usage.
```rust
use run_script::ScriptOptions;fn main() {
// simple call to run script with only the script text
let (code, output, error) = run_script::run_script!(
r#"
echo "Test"
exit 0
"#
)
.unwrap();println!("Exit Code: {}", code);
println!("Output: {}", output);
println!("Error: {}", error);// run script invoked with the script text and options
let options = ScriptOptions::new();
let (code, output, error) = run_script::run_script!(
r#"
echo "Test"
exit 0
"#,
&options
)
.unwrap();println!("Exit Code: {}", code);
println!("Output: {}", output);
println!("Error: {}", error);// run script invoked with all arguments
let options = ScriptOptions::new();
let (code, output, error) = run_script::run_script!(
r#"
echo "Test"
exit 0
"#,
&vec!["ARG1".to_string(), "ARG2".to_string()],
&options
)
.unwrap();println!("Exit Code: {}", code);
println!("Output: {}", output);
println!("Error: {}", error);// spawn_script! works the same as run_script! but returns the child process handle
let child = run_script::spawn_script!(
r#"
echo "Test"
exit 0
"#
)
.unwrap();println!("PID: {}", child.id());
}
```
## Installation
In order to use this library, just add it as a dependency:```ini
[dependencies]
run_script = "^0.11.0"
```## API Documentation
See full docs at: [API Docs](https://sagiegurari.github.io/run_script/)## Contributing
See [contributing guide](.github/CONTRIBUTING.md)See [Changelog](CHANGELOG.md)
## License
Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.