{"id":13611778,"url":"https://github.com/sagiegurari/run_script","last_synced_at":"2025-04-07T21:10:31.000Z","repository":{"id":45498135,"uuid":"109399206","full_name":"sagiegurari/run_script","owner":"sagiegurari","description":"Run shell scripts in rust.","archived":false,"fork":false,"pushed_at":"2024-10-03T11:52:15.000Z","size":4352,"stargazers_count":122,"open_issues_count":2,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T20:05:42.524Z","etag":null,"topics":["bash-script","rust","rust-library","scripting","shell-script"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sagiegurari.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-03T13:33:31.000Z","updated_at":"2025-03-17T17:06:13.000Z","dependencies_parsed_at":"2022-07-15T07:00:30.996Z","dependency_job_id":"b7a8730d-ac7a-4856-a582-5b324d502e10","html_url":"https://github.com/sagiegurari/run_script","commit_stats":{"total_commits":126,"total_committers":7,"mean_commits":18.0,"dds":0.09523809523809523,"last_synced_commit":"6745385e90b974dc49c761f29c0f94077e62017c"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Frun_script","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Frun_script/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Frun_script/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Frun_script/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sagiegurari","download_url":"https://codeload.github.com/sagiegurari/run_script/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247730068,"owners_count":20986404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash-script","rust","rust-library","scripting","shell-script"],"created_at":"2024-08-01T19:02:06.969Z","updated_at":"2025-04-07T21:10:30.973Z","avatar_url":"https://github.com/sagiegurari.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# run_script\n\n[![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)\u003cbr\u003e\n[![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)\u003cbr\u003e\n[![Built with cargo-make](https://sagiegurari.github.io/cargo-make/assets/badges/cargo-make.svg)](https://sagiegurari.github.io/cargo-make)\n\n\u003e Run shell scripts in [rust](https://www.rust-lang.org/).\n\n* [Overview](#overview)\n* [Usage](#usage)\n* [Installation](#installation)\n* [API Documentation](https://sagiegurari.github.io/run_script/)\n* [Contributing](.github/CONTRIBUTING.md)\n* [Release History](CHANGELOG.md)\n* [License](#license)\n\n\u003ca name=\"overview\"\u003e\u003c/a\u003e\n## Overview\nThis library enables to invoke shell scripts based on their content.\u003cbr\u003e\nWhile std::process::Command works great to execute standalone command, you need more manual code to take a script text and execute it.\u003cbr\u003e\nFor this purpose, this library was created.\n\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\n## Usage\nSimply include the library and invoke the run/spawn function with the script text and run options:\n\n\u003c!--{ \"examples/function_examples.rs\" | lines: 2 | code: rust }--\u003e\n```rust\nuse run_script::ScriptOptions;\n\nfn main() {\n    let options = ScriptOptions::new();\n\n    let args = vec![];\n\n    // run the script and get the script execution output\n    let (code, output, error) = run_script::run(\n        r#\"\n         echo \"Directory Info:\"\n         dir\n         \"#,\n        \u0026args,\n        \u0026options,\n    )\n    .unwrap();\n\n    println!(\"Exit Code: {}\", code);\n    println!(\"Output: {}\", output);\n    println!(\"Error: {}\", error);\n\n    // run the script and get a handle to the running child process\n    let child = run_script::spawn(\n        r#\"\n         echo \"Directory Info:\"\n         dir\n         \"#,\n        \u0026args,\n        \u0026options,\n    )\n    .unwrap();\n\n    let spawn_output = child.wait_with_output().unwrap();\n\n    println!(\"Success: {}\", \u0026spawn_output.status.success());\n}\n```\n\u003c!--{ end }--\u003e\n\nThe library also provides the **run_script!**,  **spawn_script!** and **run_script_or_exit!** macros for simpler usage.\n\n\u003c!--{ \"examples/macro_examples.rs\" | lines: 2 | code: rust }--\u003e\n```rust\nuse run_script::ScriptOptions;\n\nfn main() {\n    // simple call to run script with only the script text\n    let (code, output, error) = run_script::run_script!(\n        r#\"\n         echo \"Test\"\n         exit 0\n         \"#\n    )\n    .unwrap();\n\n    println!(\"Exit Code: {}\", code);\n    println!(\"Output: {}\", output);\n    println!(\"Error: {}\", error);\n\n    // run script invoked with the script text and options\n    let options = ScriptOptions::new();\n    let (code, output, error) = run_script::run_script!(\n        r#\"\n         echo \"Test\"\n         exit 0\n         \"#,\n        \u0026options\n    )\n    .unwrap();\n\n    println!(\"Exit Code: {}\", code);\n    println!(\"Output: {}\", output);\n    println!(\"Error: {}\", error);\n\n    // run script invoked with all arguments\n    let options = ScriptOptions::new();\n    let (code, output, error) = run_script::run_script!(\n        r#\"\n         echo \"Test\"\n         exit 0\n         \"#,\n        \u0026vec![\"ARG1\".to_string(), \"ARG2\".to_string()],\n        \u0026options\n    )\n    .unwrap();\n\n    println!(\"Exit Code: {}\", code);\n    println!(\"Output: {}\", output);\n    println!(\"Error: {}\", error);\n\n    // spawn_script! works the same as run_script! but returns the child process handle\n    let child = run_script::spawn_script!(\n        r#\"\n         echo \"Test\"\n         exit 0\n         \"#\n    )\n    .unwrap();\n\n    println!(\"PID: {}\", child.id());\n}\n```\n\u003c!--{ end }--\u003e\n\n\u003ca name=\"installation\"\u003e\u003c/a\u003e\n## Installation\nIn order to use this library, just add it as a dependency:\n\n```ini\n[dependencies]\nrun_script = \"^0.11.0\"\n```\n\n## API Documentation\nSee full docs at: [API Docs](https://sagiegurari.github.io/run_script/)\n\n## Contributing\nSee [contributing guide](.github/CONTRIBUTING.md)\n\n\u003ca name=\"history\"\u003e\u003c/a\u003e\n## Release History\n\nSee [Changelog](CHANGELOG.md)\n\n\u003ca name=\"license\"\u003e\u003c/a\u003e\n## License\nDeveloped by Sagie Gur-Ari and licensed under the Apache 2 open source license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagiegurari%2Frun_script","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsagiegurari%2Frun_script","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagiegurari%2Frun_script/lists"}