43 releases

0.10.1 Mar 1, 2023
0.10.0 Aug 6, 2022
0.9.0 Sep 13, 2021
0.8.0 May 20, 2021
0.1.6 Nov 6, 2017

#83 in Command-line interface

Download history 10588/week @ 2024-03-14 8966/week @ 2024-03-21 7146/week @ 2024-03-28 9637/week @ 2024-04-04 9001/week @ 2024-04-11 8262/week @ 2024-04-18 8379/week @ 2024-04-25 10955/week @ 2024-05-02 7319/week @ 2024-05-09 9188/week @ 2024-05-16 8538/week @ 2024-05-23 9224/week @ 2024-05-30 8581/week @ 2024-06-06 8247/week @ 2024-06-13 7032/week @ 2024-06-20 5825/week @ 2024-06-27

31,301 downloads per month
Used in 38 crates (27 directly)

Apache-2.0

1MB
998 lines

Contains (WOFF font, 400KB) NanumBarunGothic-00000000f861df9d.ttf.woff2, (WOFF font, 135KB) FiraSans-Medium-0000000066e2bc86.woff2, (WOFF font, 130KB) FiraSans-Regular-0000000084b1ad12.woff2, (WOFF font, 82KB) SourceSerif4-Bold-00000000ad926a49.ttf.woff2, (WOFF font, 77KB) SourceSerif4-Regular-0000000007da4a04.ttf.woff2, (WOFF font, 45KB) SourceCodePro-It-00000000668aca82.ttf.woff2 and 3 more.

run_script

crates.io CI codecov
license Libraries.io for GitHub Documentation downloads
Built with cargo-make

Run shell scripts in rust.

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:

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.

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:

[dependencies]
run_script = "^0.10.1"

API Documentation

See full docs at: API Docs

Contributing

See contributing guide

Release History

See Changelog

License

Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.

Dependencies

~1.5MB