43 个版本

0.10.1 2023 年 3 月 1 日
0.10.0 2022 年 8 月 6 日
0.9.0 2021 年 9 月 13 日
0.8.0 2021 年 5 月 20 日
0.1.6 2017 年 11 月 6 日

83命令行界面

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 个月下载量
用于 38 个 Crates(27 个直接使用)

Apache-2.0

1MB
998

包含 (WOFF 字体,400KB) NanumBarunGothic-00000000f861df9d.ttf.woff2,(WOFF 字体,135KB) FiraSans-Medium-0000000066e2bc86.woff2,(WOFF 字体,130KB) FiraSans-Regular-0000000084b1ad12.woff2,(WOFF 字体,82KB) SourceSerif4-Bold-00000000ad926a49.ttf.woff2,(WOFF 字体,77KB) SourceSerif4-Regular-0000000007da4a04.ttf.woff2,(WOFF 字体,45KB) SourceCodePro-It-00000000668aca82.ttf.woff2 和更多

run_script

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

rust 中运行 shell 脚本。

概述

此库允许根据其内容调用 shell 脚本。
虽然 std::process::Command 在执行独立命令时表现良好,但您需要更多的手动代码来获取脚本文本并执行它。
为此,创建了此库。

用法

只需包含库,并使用脚本文本和运行选项调用 run/spawn 函数

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());
}

此库还提供了 run_script!spawn_script!run_script_or_exit! 宏,以实现更简单的使用。

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());
}

安装

为了使用此库,只需将其添加为依赖项

[dependencies]
run_script = "^0.10.1"

API 文档

请参阅完整文档: API 文档

贡献

请参阅 贡献指南

版本历史

请参阅 变更日志

许可证

由 Sagie Gur-Ari 开发并许可在 Apache 2 开源许可证下。

依赖项

~1.5MB