├── docs ├── api │ ├── .lock │ ├── crates.js │ ├── run_script │ │ ├── types │ │ │ ├── sidebar-items.js │ │ │ ├── index.html │ │ │ └── type.ScriptResult.html │ │ ├── sidebar-items.js │ │ ├── macro.run_script!.html │ │ ├── macro.spawn_script!.html │ │ ├── macro.run_script_or_exit!.html │ │ ├── all.html │ │ ├── type.IoOptions.html │ │ ├── macro.spawn_script.html │ │ ├── type.ScriptError.html │ │ ├── fn.spawn.html │ │ ├── fn.run_or_exit.html │ │ ├── macro.run_script.html │ │ ├── macro.run_script_or_exit.html │ │ ├── fn.run.html │ │ └── type.ScriptOptions.html │ ├── src-files.js │ ├── static.files │ │ ├── favicon-32x32-6580c154.png │ │ ├── FiraMono-Medium-86f75c8c.woff2 │ │ ├── FiraSans-Italic-81dc35de.woff2 │ │ ├── FiraSans-Medium-e1aa3f0a.woff2 │ │ ├── FiraMono-Regular-87c26294.woff2 │ │ ├── FiraSans-Regular-0fe48ade.woff2 │ │ ├── NanumBarunGothic-13b3dcba.ttf.woff2 │ │ ├── SourceCodePro-It-fc8b9304.ttf.woff2 │ │ ├── SourceSerif4-It-ca3b17ed.ttf.woff2 │ │ ├── FiraSans-MediumItalic-ccf7e434.woff2 │ │ ├── SourceSerif4-Bold-6d4fd4c0.ttf.woff2 │ │ ├── SourceCodePro-Regular-8badfe75.ttf.woff2 │ │ ├── SourceSerif4-Regular-6b053e98.ttf.woff2 │ │ ├── SourceSerif4-Semibold-457a13ac.ttf.woff2 │ │ ├── SourceCodePro-Semibold-aa29a496.ttf.woff2 │ │ ├── LICENSE-MIT-23f18e03.txt │ │ ├── normalize-9960930a.css │ │ ├── scrape-examples-5e967b76.js │ │ ├── COPYRIGHT-7fb11f4e.txt │ │ ├── rust-logo-9a9549ea.svg │ │ ├── src-script-813739b1.js │ │ ├── favicon-044be391.svg │ │ ├── FiraSans-LICENSE-05ab6dbd.txt │ │ ├── SourceCodePro-LICENSE-67f54ca7.txt │ │ ├── SourceSerif4-LICENSE-a2cfd9d5.md │ │ ├── NanumBarunGothic-LICENSE-a37d393b.txt │ │ ├── storage-68b7e25d.js │ │ ├── settings-5514c975.js │ │ └── noscript-32bb7600.css │ ├── trait.impl │ │ └── core │ │ │ ├── marker │ │ │ ├── trait.Copy.js │ │ │ ├── trait.UnsafeUnpin.js │ │ │ ├── trait.StructuralPartialEq.js │ │ │ ├── trait.Send.js │ │ │ ├── trait.Sync.js │ │ │ ├── trait.Unpin.js │ │ │ └── trait.Freeze.js │ │ │ ├── error │ │ │ └── trait.Error.js │ │ │ ├── fmt │ │ │ ├── trait.Display.js │ │ │ └── trait.Debug.js │ │ │ ├── clone │ │ │ └── trait.Clone.js │ │ │ ├── cmp │ │ │ └── trait.PartialEq.js │ │ │ └── panic │ │ │ └── unwind_safe │ │ │ ├── trait.UnwindSafe.js │ │ │ └── trait.RefUnwindSafe.js │ ├── search.desc │ │ └── run_script │ │ │ └── run_script-desc-0-.js │ ├── search-index.js │ ├── settings.html │ ├── help.html │ └── type.impl │ │ └── run_script │ │ └── types │ │ ├── enum.IoOptions.js │ │ ├── struct.ScriptOptions.js │ │ └── enum.ScriptError.js └── index.html ├── .gitattributes ├── .rusty-hook.toml ├── .gitignore ├── .github ├── dependabot.yml ├── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── workflows │ └── ci.yml └── CONTRIBUTING.md ├── .editorconfig ├── Makefile.toml ├── tests ├── run_test.rs ├── run_script_or_exit_macro_test.rs ├── run_script_macro_test.rs └── spawn_script_macro_test.rs ├── benches └── bench_run.rs ├── src ├── types_test.rs ├── lib_test.rs ├── types.rs ├── macros.rs └── lib.rs ├── examples ├── function_examples.rs └── macro_examples.rs ├── Cargo.toml ├── CHANGELOG.md └── README.md /docs/api/.lock: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=lf 2 | *.ico binary 3 | *.woff binary 4 | -------------------------------------------------------------------------------- /.rusty-hook.toml: -------------------------------------------------------------------------------- 1 | [hooks] 2 | pre-push = "cargo make ci-flow" 3 | -------------------------------------------------------------------------------- /docs/api/crates.js: -------------------------------------------------------------------------------- 1 | window.ALL_CRATES = ["run_script"]; 2 | //{"start":21,"fragment_lengths":[12]} -------------------------------------------------------------------------------- /docs/api/run_script/types/sidebar-items.js: -------------------------------------------------------------------------------- 1 | window.SIDEBAR_ITEMS = {"enum":["IoOptions","ScriptError"],"struct":["ScriptOptions"],"type":["ScriptResult"]}; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .c9 3 | /target 4 | temp/ 5 | **/*.rs.bk 6 | Cargo.lock 7 | **/*.log 8 | dump.rdb 9 | /rs*.sh 10 | /docs/_site 11 | /core 12 | -------------------------------------------------------------------------------- /docs/api/src-files.js: -------------------------------------------------------------------------------- 1 | createSrcSidebar('[["run_script",["",[],["lib.rs","macros.rs","runner.rs","types.rs"]]]]'); 2 | //{"start":19,"fragment_lengths":[68]} -------------------------------------------------------------------------------- /docs/api/static.files/favicon-32x32-6580c154.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/run_script/HEAD/docs/api/static.files/favicon-32x32-6580c154.png -------------------------------------------------------------------------------- /docs/api/static.files/FiraMono-Medium-86f75c8c.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/run_script/HEAD/docs/api/static.files/FiraMono-Medium-86f75c8c.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/FiraSans-Italic-81dc35de.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/run_script/HEAD/docs/api/static.files/FiraSans-Italic-81dc35de.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/FiraSans-Medium-e1aa3f0a.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/run_script/HEAD/docs/api/static.files/FiraSans-Medium-e1aa3f0a.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/FiraMono-Regular-87c26294.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/run_script/HEAD/docs/api/static.files/FiraMono-Regular-87c26294.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/FiraSans-Regular-0fe48ade.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/run_script/HEAD/docs/api/static.files/FiraSans-Regular-0fe48ade.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/NanumBarunGothic-13b3dcba.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/run_script/HEAD/docs/api/static.files/NanumBarunGothic-13b3dcba.ttf.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/SourceCodePro-It-fc8b9304.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/run_script/HEAD/docs/api/static.files/SourceCodePro-It-fc8b9304.ttf.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/SourceSerif4-It-ca3b17ed.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/run_script/HEAD/docs/api/static.files/SourceSerif4-It-ca3b17ed.ttf.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/FiraSans-MediumItalic-ccf7e434.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/run_script/HEAD/docs/api/static.files/FiraSans-MediumItalic-ccf7e434.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/SourceSerif4-Bold-6d4fd4c0.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/run_script/HEAD/docs/api/static.files/SourceSerif4-Bold-6d4fd4c0.ttf.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/SourceCodePro-Regular-8badfe75.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/run_script/HEAD/docs/api/static.files/SourceCodePro-Regular-8badfe75.ttf.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/SourceSerif4-Regular-6b053e98.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/run_script/HEAD/docs/api/static.files/SourceSerif4-Regular-6b053e98.ttf.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/SourceSerif4-Semibold-457a13ac.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/run_script/HEAD/docs/api/static.files/SourceSerif4-Semibold-457a13ac.ttf.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/SourceCodePro-Semibold-aa29a496.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/run_script/HEAD/docs/api/static.files/SourceCodePro-Semibold-aa29a496.ttf.woff2 -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: cargo 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: '03:00' 8 | open-pull-requests-limit: 99 9 | -------------------------------------------------------------------------------- /docs/api/run_script/sidebar-items.js: -------------------------------------------------------------------------------- 1 | window.SIDEBAR_ITEMS = {"fn":["run","run_or_exit","spawn"],"macro":["run_script","run_script_or_exit","spawn_script"],"mod":["types"],"type":["IoOptions","ScriptError","ScriptOptions"]}; -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | indent_style = space 10 | indent_size = 4 11 | 12 | [*.json] 13 | indent_size = 2 14 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Makefile.toml: -------------------------------------------------------------------------------- 1 | 2 | [config] 3 | additional_profiles = [ 4 | "all-default-tasks", 5 | "docs-all-modification-tasks", 6 | "ci-coverage-tasks", 7 | "ci-all-build-tasks", 8 | "ci-static-code-analysis-tasks", 9 | "publish-pre-cleanup", 10 | ] 11 | -------------------------------------------------------------------------------- /docs/api/run_script/macro.run_script!.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Redirection 6 | 7 | 8 |

Redirecting to macro.run_script.html...

9 | 10 | 11 | -------------------------------------------------------------------------------- /docs/api/run_script/macro.spawn_script!.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Redirection 6 | 7 | 8 |

Redirecting to macro.spawn_script.html...

9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: sagiegurari 7 | 8 | --- 9 | 10 | ### Feature Description 11 | 12 | 13 | ### Describe The Solution You'd Like 14 | 15 | 16 | ### Code Sample 17 | 18 | ```rust 19 | /// paste code here 20 | ``` 21 | -------------------------------------------------------------------------------- /docs/api/run_script/macro.run_script_or_exit!.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Redirection 6 | 7 | 8 |

Redirecting to macro.run_script_or_exit.html...

9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/run_test.rs: -------------------------------------------------------------------------------- 1 | use run_script; 2 | use run_script::ScriptOptions; 3 | 4 | #[test] 5 | fn run_test() { 6 | let args = vec![]; 7 | let options = ScriptOptions::new(); 8 | 9 | let (code, output, error) = run_script::run( 10 | r#" 11 | echo "Test" 12 | exit 0 13 | "#, 14 | &args, 15 | &options, 16 | ) 17 | .unwrap(); 18 | 19 | assert_eq!(code, 0); 20 | assert!(output.len() > 0); 21 | assert_eq!(error.len(), 0); 22 | } 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: sagiegurari 7 | 8 | --- 9 | 10 | ### Describe The Bug 11 | 12 | 13 | ### To Reproduce 14 | 15 | 16 | ### Error Stack 17 | 18 | ```console 19 | The error stack trace 20 | ``` 21 | 22 | ### Code Sample 23 | 24 | ```rust 25 | /// paste code here 26 | ``` 27 | -------------------------------------------------------------------------------- /docs/api/trait.impl/core/marker/trait.Copy.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var implementors = Object.fromEntries([["run_script",[["impl Copy for IoOptions"]]]]); 3 | if (window.register_implementors) { 4 | window.register_implementors(implementors); 5 | } else { 6 | window.pending_implementors = implementors; 7 | } 8 | })() 9 | //{"start":57,"fragment_lengths":[284]} -------------------------------------------------------------------------------- /docs/api/trait.impl/core/error/trait.Error.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var implementors = Object.fromEntries([["run_script",[["impl Error for ScriptError"]]]]); 3 | if (window.register_implementors) { 4 | window.register_implementors(implementors); 5 | } else { 6 | window.pending_implementors = implementors; 7 | } 8 | })() 9 | //{"start":57,"fragment_lengths":[291]} -------------------------------------------------------------------------------- /docs/api/trait.impl/core/fmt/trait.Display.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var implementors = Object.fromEntries([["run_script",[["impl Display for ScriptError"]]]]); 3 | if (window.register_implementors) { 4 | window.register_implementors(implementors); 5 | } else { 6 | window.pending_implementors = implementors; 7 | } 8 | })() 9 | //{"start":57,"fragment_lengths":[293]} -------------------------------------------------------------------------------- /benches/bench_run.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use run_script; 5 | use run_script::ScriptOptions; 6 | use test::Bencher; 7 | 8 | #[bench] 9 | fn run(bencher: &mut Bencher) { 10 | let options = ScriptOptions::new(); 11 | 12 | let args = vec![]; 13 | 14 | bencher.iter(|| { 15 | let (code, output, error) = run_script::run( 16 | r#" 17 | echo "Test" 18 | exit 0 19 | "#, 20 | &args, 21 | &options, 22 | ) 23 | .unwrap(); 24 | 25 | assert_eq!(code, 0); 26 | assert!(output.len() > 0); 27 | assert_eq!(error.len(), 0); 28 | }); 29 | } 30 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: [push, pull_request] 3 | env: 4 | CLICOLOR_FORCE: 1 5 | jobs: 6 | ci: 7 | name: CI 8 | runs-on: ${{ matrix.os }} 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | rust: [stable, beta, nightly] 13 | os: [ubuntu-latest, windows-latest, macOS-latest] 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v4 17 | - name: Install rust 18 | uses: dtolnay/rust-toolchain@master 19 | with: 20 | toolchain: ${{ matrix.rust }} 21 | - name: Install cargo-make 22 | run: cargo install --debug cargo-make 23 | - name: Run CI 24 | env: 25 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} 26 | run: cargo make ci-flow 27 | -------------------------------------------------------------------------------- /docs/api/trait.impl/core/clone/trait.Clone.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var implementors = Object.fromEntries([["run_script",[["impl Clone for IoOptions"],["impl Clone for ScriptOptions"]]]]); 3 | if (window.register_implementors) { 4 | window.register_implementors(implementors); 5 | } else { 6 | window.pending_implementors = implementors; 7 | } 8 | })() 9 | //{"start":57,"fragment_lengths":[572]} -------------------------------------------------------------------------------- /docs/api/trait.impl/core/cmp/trait.PartialEq.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var implementors = Object.fromEntries([["run_script",[["impl PartialEq for IoOptions"],["impl PartialEq for ScriptOptions"]]]]); 3 | if (window.register_implementors) { 4 | window.register_implementors(implementors); 5 | } else { 6 | window.pending_implementors = implementors; 7 | } 8 | })() 9 | //{"start":57,"fragment_lengths":[588]} -------------------------------------------------------------------------------- /docs/api/trait.impl/core/marker/trait.UnsafeUnpin.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var implementors = Object.fromEntries([["run_script",[["impl UnsafeUnpin for IoOptions",1,["run_script::types::IoOptions"]],["impl UnsafeUnpin for ScriptError",1,["run_script::types::ScriptError"]],["impl UnsafeUnpin for ScriptOptions",1,["run_script::types::ScriptOptions"]]]]]); 3 | if (window.register_implementors) { 4 | window.register_implementors(implementors); 5 | } else { 6 | window.pending_implementors = implementors; 7 | } 8 | })() 9 | //{"start":57,"fragment_lengths":[592]} -------------------------------------------------------------------------------- /src/types_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use std::error::Error; 3 | use std::io::Write; 4 | 5 | #[test] 6 | fn script_error_description() { 7 | let script_error = ScriptError::Description("test"); 8 | 9 | assert_eq!(script_error.to_string(), "test"); 10 | assert!(script_error.source().is_none()); 11 | 12 | let mut writer = Vec::new(); 13 | write!(&mut writer, "formatted {}", script_error).unwrap(); 14 | assert_eq!(writer, b"formatted test"); 15 | } 16 | 17 | #[test] 18 | fn script_options_new() { 19 | let options = ScriptOptions::new(); 20 | 21 | assert!(options.runner.is_none()); 22 | assert!(options.working_directory.is_none()); 23 | assert_eq!(options.input_redirection, IoOptions::Inherit); 24 | assert_eq!(options.output_redirection, IoOptions::Pipe); 25 | assert!(!options.exit_on_error); 26 | assert!(!options.print_commands); 27 | #[cfg(feature = "encoding_rs")] 28 | assert!(options.encoding.is_none()); 29 | } 30 | -------------------------------------------------------------------------------- /docs/api/trait.impl/core/marker/trait.StructuralPartialEq.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var implementors = Object.fromEntries([["run_script",[["impl StructuralPartialEq for IoOptions"],["impl StructuralPartialEq for ScriptOptions"]]]]); 3 | if (window.register_implementors) { 4 | window.register_implementors(implementors); 5 | } else { 6 | window.pending_implementors = implementors; 7 | } 8 | })() 9 | //{"start":57,"fragment_lengths":[660]} -------------------------------------------------------------------------------- /examples/function_examples.rs: -------------------------------------------------------------------------------- 1 | use run_script; 2 | use run_script::ScriptOptions; 3 | 4 | fn main() { 5 | let options = ScriptOptions::new(); 6 | 7 | let args = vec![]; 8 | 9 | // run the script and get the script execution output 10 | let (code, output, error) = run_script::run( 11 | r#" 12 | echo "Directory Info:" 13 | dir 14 | "#, 15 | &args, 16 | &options, 17 | ) 18 | .unwrap(); 19 | 20 | println!("Exit Code: {}", code); 21 | println!("Output: {}", output); 22 | println!("Error: {}", error); 23 | 24 | // run the script and get a handle to the running child process 25 | let child = run_script::spawn( 26 | r#" 27 | echo "Directory Info:" 28 | dir 29 | "#, 30 | &args, 31 | &options, 32 | ) 33 | .unwrap(); 34 | 35 | let spawn_output = child.wait_with_output().unwrap(); 36 | 37 | println!("Success: {}", &spawn_output.status.success()); 38 | } 39 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidelines 2 | 3 | 4 | ## Issues 5 | 6 | Found a bug? Got a question? Want some enhancement?
7 | First place to go is the repository issues section, and I'll try to help as much as possible. 8 | 9 | ## Pull Requests 10 | 11 | Fixed a bug or just want to provided additional functionality?
12 | Simply fork this repository, implement your changes and create a pull request.
13 | Few guidelines regarding pull requests: 14 | 15 | * This repository is integrated with github actions for continuous integration.
16 | 17 | Your pull request build must pass (the build will run automatically).
18 | You can run the following command locally to ensure the build will pass: 19 | 20 | ````sh 21 | cargo make ci-flow 22 | ```` 23 | 24 | * There are many automatic unit tests as part of the library which provide full coverage of the functionality.
Any fix/enhancement must come with a set of tests to ensure it's working well. 25 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "run_script" 3 | version = "0.11.2" 4 | authors = ["Sagie Gur-Ari "] 5 | description = "Run shell scripts in rust." 6 | license = "Apache-2.0" 7 | edition = "2021" 8 | documentation = "https://sagiegurari.github.io/run_script/api/run_script/index.html" 9 | homepage = "http://github.com/sagiegurari/run_script" 10 | repository = "https://github.com/sagiegurari/run_script.git" 11 | readme = "README.md" 12 | keywords = ["shell", "scripts", "os", "command", "runner"] 13 | categories = ["command-line-interface", "command-line-utilities"] 14 | include = [ 15 | "/benches/*", 16 | "/examples/*", 17 | "/src/*", 18 | "/tests/*", 19 | "/Cargo.toml", 20 | "/LICENSE", 21 | "/README.md", 22 | "/Makefile.toml", 23 | ] 24 | 25 | [dependencies] 26 | fsio = { version = "^0.4", features = ["temp-path"] } 27 | encoding_rs = { version = "0.8.35", default-features = false, features = [ 28 | "alloc", 29 | ], optional = true } 30 | 31 | [dev-dependencies] 32 | doc-comment = "^0.3" 33 | -------------------------------------------------------------------------------- /docs/api/trait.impl/core/fmt/trait.Debug.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var implementors = Object.fromEntries([["run_script",[["impl Debug for IoOptions"],["impl Debug for ScriptError"],["impl Debug for ScriptOptions"]]]]); 3 | if (window.register_implementors) { 4 | window.register_implementors(implementors); 5 | } else { 6 | window.pending_implementors = implementors; 7 | } 8 | })() 9 | //{"start":57,"fragment_lengths":[835]} -------------------------------------------------------------------------------- /docs/api/static.files/LICENSE-MIT-23f18e03.txt: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any 2 | person obtaining a copy of this software and associated 3 | documentation files (the "Software"), to deal in the 4 | Software without restriction, including without 5 | limitation the rights to use, copy, modify, merge, 6 | publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software 8 | is furnished to do so, subject to the following 9 | conditions: 10 | 11 | The above copyright notice and this permission notice 12 | shall be included in all copies or substantial portions 13 | of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 16 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 17 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 18 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 19 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /docs/api/trait.impl/core/marker/trait.Send.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var implementors = Object.fromEntries([["run_script",[["impl Send for IoOptions",1,["run_script::types::IoOptions"]],["impl Send for ScriptError",1,["run_script::types::ScriptError"]],["impl Send for ScriptOptions",1,["run_script::types::ScriptOptions"]]]]]); 3 | if (window.register_implementors) { 4 | window.register_implementors(implementors); 5 | } else { 6 | window.pending_implementors = implementors; 7 | } 8 | })() 9 | //{"start":57,"fragment_lengths":[955]} -------------------------------------------------------------------------------- /docs/api/trait.impl/core/marker/trait.Sync.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var implementors = Object.fromEntries([["run_script",[["impl Sync for IoOptions",1,["run_script::types::IoOptions"]],["impl Sync for ScriptError",1,["run_script::types::ScriptError"]],["impl Sync for ScriptOptions",1,["run_script::types::ScriptOptions"]]]]]); 3 | if (window.register_implementors) { 4 | window.register_implementors(implementors); 5 | } else { 6 | window.pending_implementors = implementors; 7 | } 8 | })() 9 | //{"start":57,"fragment_lengths":[955]} -------------------------------------------------------------------------------- /docs/api/trait.impl/core/marker/trait.Unpin.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var implementors = Object.fromEntries([["run_script",[["impl Unpin for IoOptions",1,["run_script::types::IoOptions"]],["impl Unpin for ScriptError",1,["run_script::types::ScriptError"]],["impl Unpin for ScriptOptions",1,["run_script::types::ScriptOptions"]]]]]); 3 | if (window.register_implementors) { 4 | window.register_implementors(implementors); 5 | } else { 6 | window.pending_implementors = implementors; 7 | } 8 | })() 9 | //{"start":57,"fragment_lengths":[964]} -------------------------------------------------------------------------------- /docs/api/trait.impl/core/marker/trait.Freeze.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var implementors = Object.fromEntries([["run_script",[["impl Freeze for IoOptions",1,["run_script::types::IoOptions"]],["impl Freeze for ScriptError",1,["run_script::types::ScriptError"]],["impl Freeze for ScriptOptions",1,["run_script::types::ScriptOptions"]]]]]); 3 | if (window.register_implementors) { 4 | window.register_implementors(implementors); 5 | } else { 6 | window.pending_implementors = implementors; 7 | } 8 | })() 9 | //{"start":57,"fragment_lengths":[973]} -------------------------------------------------------------------------------- /docs/api/trait.impl/core/panic/unwind_safe/trait.UnwindSafe.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var implementors = Object.fromEntries([["run_script",[["impl !UnwindSafe for ScriptError",1,["run_script::types::ScriptError"]],["impl UnwindSafe for IoOptions",1,["run_script::types::IoOptions"]],["impl UnwindSafe for ScriptOptions",1,["run_script::types::ScriptOptions"]]]]]); 3 | if (window.register_implementors) { 4 | window.register_implementors(implementors); 5 | } else { 6 | window.pending_implementors = implementors; 7 | } 8 | })() 9 | //{"start":57,"fragment_lengths":[1079]} -------------------------------------------------------------------------------- /docs/api/trait.impl/core/panic/unwind_safe/trait.RefUnwindSafe.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var implementors = Object.fromEntries([["run_script",[["impl !RefUnwindSafe for ScriptError",1,["run_script::types::ScriptError"]],["impl RefUnwindSafe for IoOptions",1,["run_script::types::IoOptions"]],["impl RefUnwindSafe for ScriptOptions",1,["run_script::types::ScriptOptions"]]]]]); 3 | if (window.register_implementors) { 4 | window.register_implementors(implementors); 5 | } else { 6 | window.pending_implementors = implementors; 7 | } 8 | })() 9 | //{"start":57,"fragment_lengths":[1106]} -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## CHANGELOG 2 | 3 | ### v0.11.2 (2025-10-14) 4 | 5 | * Enhancement: add encoding conversion #27 (thanks @TerakomariGandesblood) 6 | 7 | ### v0.11.0 (2024-10-03) 8 | 9 | * Enhancement: support options.print_commands on Windows #26 (thanks @sadboy) 10 | 11 | ### v0.10.1 (2023-03-01) 12 | 13 | * Enhancement: support runner arguments #20 (thanks @aria-aghaei) 14 | 15 | ### v0.10.0 (2022-08-06) 16 | 17 | * Update dependencies 18 | 19 | ### v0.9.0 (2021-09-13) 20 | 21 | * Add windows UNC path support (fsio upgrade) 22 | 23 | ### v0.8.0 (2021-05-20) 24 | 25 | * Support providing environment variables to script process #16 (thanks @kenr) 26 | 27 | ### v0.7.0 (2021-03-09) 28 | 29 | * Make script error chainable. 30 | 31 | ### v0.6.4 (2021-02-23) 32 | 33 | * Fix issue with CWD containing spaces. 34 | 35 | ### v0.6.3 (2020-05-14) 36 | 37 | * Support custom working directory #13 38 | 39 | ### v0.6.2 (2020-02-17) 40 | 41 | * Use fsio crate for file system apis. 42 | 43 | ### v0.6.1 (2020-02-08) 44 | 45 | * New run_or_exit function and run_script_or_exit macro #10 46 | 47 | ### v0.6.0 (2020-01-18) 48 | 49 | * Rust upgrade 50 | 51 | ### v0.5.0 (2020-01-06) 52 | 53 | * New input/output redirection options #9 54 | 55 | ### v0.4.0 (2019-12-24) 56 | 57 | * New spawn function and spawn_script! macro #7 58 | 59 | ### v0.1.14 (2018-03-20) 60 | 61 | * Fix permissions issue #2 62 | 63 | ### v0.1.10 (2017-12-23) 64 | 65 | * New run_script! macro 66 | 67 | ### v0.1.1 (2017-11-04) 68 | 69 | * Initial release. 70 | -------------------------------------------------------------------------------- /src/lib_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use doc_comment as _; 3 | 4 | #[test] 5 | fn run_test() { 6 | let args = vec![]; 7 | let options = ScriptOptions::new(); 8 | 9 | let (code, output, error) = run( 10 | r#" 11 | echo "Test" 12 | exit 0 13 | "#, 14 | &args, 15 | &options, 16 | ) 17 | .unwrap(); 18 | 19 | assert_eq!(code, 0); 20 | assert!(output.len() > 0); 21 | assert_eq!(error.len(), 0); 22 | } 23 | 24 | #[test] 25 | fn spawn_test_valid_exit_code() { 26 | let args = vec![]; 27 | let options = ScriptOptions::new(); 28 | 29 | let child = spawn( 30 | r#" 31 | echo "Test" 32 | exit 0 33 | "#, 34 | &args, 35 | &options, 36 | ) 37 | .unwrap(); 38 | 39 | let output = child.wait_with_output().unwrap(); 40 | assert!(output.status.success()); 41 | } 42 | 43 | #[test] 44 | #[should_panic] 45 | fn run_or_exit_error_code() { 46 | let args = vec![]; 47 | let options = ScriptOptions::new(); 48 | 49 | run_or_exit("exit 1", &args, &options); 50 | } 51 | 52 | #[test] 53 | fn run_or_exit_pipe_output() { 54 | let args = vec![]; 55 | let mut options = ScriptOptions::new(); 56 | options.output_redirection = IoOptions::Pipe; 57 | 58 | let (output, error) = run_or_exit( 59 | r#" 60 | echo "Test" 61 | exit 0 62 | "#, 63 | &args, 64 | &options, 65 | ); 66 | 67 | assert!(!output.is_empty()); 68 | assert!(error.is_empty()); 69 | } 70 | -------------------------------------------------------------------------------- /tests/run_script_or_exit_macro_test.rs: -------------------------------------------------------------------------------- 1 | use run_script; 2 | use run_script::ScriptOptions; 3 | 4 | #[test] 5 | fn run_script_or_exit_macro_no_args_no_options_valid() { 6 | let (output, error) = run_script::run_script_or_exit!( 7 | r#" 8 | echo "Test" 9 | exit 0 10 | "# 11 | ); 12 | 13 | assert!(output.len() > 0); 14 | assert_eq!(error.len(), 0); 15 | } 16 | 17 | #[test] 18 | fn run_script_or_exit_macro_no_args_with_options() { 19 | let options = ScriptOptions::new(); 20 | 21 | let (output, error) = run_script::run_script_or_exit!( 22 | r#" 23 | echo "Test" 24 | exit 0 25 | "#, 26 | options 27 | ); 28 | 29 | assert!(output.len() > 0); 30 | assert_eq!(error.len(), 0); 31 | } 32 | 33 | #[test] 34 | fn run_script_or_exit_macro_with_args_with_options() { 35 | let options = ScriptOptions::new(); 36 | 37 | let script = if cfg!(windows) { 38 | r#" 39 | echo arg1: %1 40 | echo arg2: %2 41 | exit 0 42 | "# 43 | } else { 44 | r#" 45 | echo arg1: $1 46 | echo arg2: $2 47 | exit 0 48 | "# 49 | }; 50 | 51 | let (output, error) = run_script::run_script_or_exit!( 52 | &script, 53 | &vec!["ARG1".to_string(), "ARG2".to_string()], 54 | options 55 | ); 56 | 57 | assert!(output.len() > 0); 58 | assert_eq!(error.len(), 0); 59 | 60 | assert!(output.find("arg1: ARG1").is_some()); 61 | assert!(output.find("arg2: ARG2").is_some()); 62 | } 63 | -------------------------------------------------------------------------------- /examples/macro_examples.rs: -------------------------------------------------------------------------------- 1 | use run_script; 2 | use run_script::ScriptOptions; 3 | 4 | fn main() { 5 | // simple call to run script with only the script text 6 | let (code, output, error) = run_script::run_script!( 7 | r#" 8 | echo "Test" 9 | exit 0 10 | "# 11 | ) 12 | .unwrap(); 13 | 14 | println!("Exit Code: {}", code); 15 | println!("Output: {}", output); 16 | println!("Error: {}", error); 17 | 18 | // run script invoked with the script text and options 19 | let options = ScriptOptions::new(); 20 | let (code, output, error) = run_script::run_script!( 21 | r#" 22 | echo "Test" 23 | exit 0 24 | "#, 25 | &options 26 | ) 27 | .unwrap(); 28 | 29 | println!("Exit Code: {}", code); 30 | println!("Output: {}", output); 31 | println!("Error: {}", error); 32 | 33 | // run script invoked with all arguments 34 | let options = ScriptOptions::new(); 35 | let (code, output, error) = run_script::run_script!( 36 | r#" 37 | echo "Test" 38 | exit 0 39 | "#, 40 | &vec!["ARG1".to_string(), "ARG2".to_string()], 41 | &options 42 | ) 43 | .unwrap(); 44 | 45 | println!("Exit Code: {}", code); 46 | println!("Output: {}", output); 47 | println!("Error: {}", error); 48 | 49 | // spawn_script! works the same as run_script! but returns the child process handle 50 | let child = run_script::spawn_script!( 51 | r#" 52 | echo "Test" 53 | exit 0 54 | "# 55 | ) 56 | .unwrap(); 57 | 58 | println!("PID: {}", child.id()); 59 | } 60 | -------------------------------------------------------------------------------- /docs/api/static.files/normalize-9960930a.css: -------------------------------------------------------------------------------- 1 | /*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */ 2 | html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:block}h1{font-size:2em;margin:0.67em 0}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-0.25em}sup{top:-0.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}[type="button"],[type="reset"],[type="submit"],button{-webkit-appearance:button}[type="button"]::-moz-focus-inner,[type="reset"]::-moz-focus-inner,[type="submit"]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type="button"]:-moz-focusring,[type="reset"]:-moz-focusring,[type="submit"]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:0.35em 0.75em 0.625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{vertical-align:baseline}textarea{overflow:auto}[type="checkbox"],[type="radio"]{box-sizing:border-box;padding:0}[type="number"]::-webkit-inner-spin-button,[type="number"]::-webkit-outer-spin-button{height:auto}[type="search"]{-webkit-appearance:textfield;outline-offset:-2px}[type="search"]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none} -------------------------------------------------------------------------------- /tests/run_script_macro_test.rs: -------------------------------------------------------------------------------- 1 | use run_script; 2 | use run_script::ScriptOptions; 3 | 4 | #[test] 5 | fn run_macro_no_args_no_options_valid() { 6 | let (code, output, error) = run_script::run_script!( 7 | r#" 8 | echo "Test" 9 | exit 0 10 | "# 11 | ) 12 | .unwrap(); 13 | 14 | assert_eq!(code, 0); 15 | assert!(output.len() > 0); 16 | assert_eq!(error.len(), 0); 17 | } 18 | 19 | #[test] 20 | fn run_macro_no_args_no_options_error_output() { 21 | let output = run_script::run_script!( 22 | r#" 23 | echo "Test" 24 | exit 123 25 | "# 26 | ) 27 | .unwrap(); 28 | let code = output.0; 29 | 30 | assert_eq!(code, 123); 31 | } 32 | 33 | #[test] 34 | fn run_macro_no_args_with_options() { 35 | let options = ScriptOptions::new(); 36 | 37 | let (code, output, error) = run_script::run_script!( 38 | r#" 39 | echo "Test" 40 | exit 0 41 | "#, 42 | options 43 | ) 44 | .unwrap(); 45 | 46 | assert_eq!(code, 0); 47 | assert!(output.len() > 0); 48 | assert_eq!(error.len(), 0); 49 | } 50 | 51 | #[test] 52 | fn run_macro_with_args_with_options() { 53 | let options = ScriptOptions::new(); 54 | 55 | let script = if cfg!(windows) { 56 | r#" 57 | echo arg1: %1 58 | echo arg2: %2 59 | exit 0 60 | "# 61 | } else { 62 | r#" 63 | echo arg1: $1 64 | echo arg2: $2 65 | exit 0 66 | "# 67 | }; 68 | 69 | let (code, output, error) = run_script::run_script!( 70 | &script, 71 | &vec!["ARG1".to_string(), "ARG2".to_string()], 72 | options 73 | ) 74 | .unwrap(); 75 | 76 | assert_eq!(code, 0); 77 | assert!(output.len() > 0); 78 | assert_eq!(error.len(), 0); 79 | 80 | assert!(output.find("arg1: ARG1").is_some()); 81 | assert!(output.find("arg2: ARG2").is_some()); 82 | } 83 | -------------------------------------------------------------------------------- /tests/spawn_script_macro_test.rs: -------------------------------------------------------------------------------- 1 | use run_script; 2 | use run_script::ScriptOptions; 3 | 4 | #[test] 5 | fn spawn_macro_no_args_no_options_valid() { 6 | let child = run_script::spawn_script!( 7 | r#" 8 | echo "Test" 9 | exit 0 10 | "# 11 | ) 12 | .unwrap(); 13 | 14 | let output = child.wait_with_output().unwrap(); 15 | 16 | assert!(output.status.success()); 17 | } 18 | 19 | #[test] 20 | fn spawn_macro_no_args_no_options_error_output() { 21 | let child = run_script::spawn_script!( 22 | r#" 23 | echo "Test" 24 | exit 123 25 | "# 26 | ) 27 | .unwrap(); 28 | 29 | let output = child.wait_with_output().unwrap(); 30 | 31 | assert_eq!(output.status.code().unwrap(), 123); 32 | } 33 | 34 | #[test] 35 | fn spawn_macro_no_args_with_options() { 36 | let options = ScriptOptions::new(); 37 | 38 | let child = run_script::spawn_script!( 39 | r#" 40 | echo "Test" 41 | exit 0 42 | "#, 43 | options 44 | ) 45 | .unwrap(); 46 | 47 | let output = child.wait_with_output().unwrap(); 48 | 49 | assert!(output.status.success()); 50 | assert!(output.stdout.len() > 0); 51 | } 52 | 53 | #[test] 54 | fn spawn_macro_with_args_with_options() { 55 | let options = ScriptOptions::new(); 56 | 57 | let script = if cfg!(windows) { 58 | r#" 59 | echo arg1: %1 60 | echo arg2: %2 61 | exit 0 62 | "# 63 | } else { 64 | r#" 65 | echo arg1: $1 66 | echo arg2: $2 67 | exit 0 68 | "# 69 | }; 70 | 71 | let child = run_script::spawn_script!( 72 | &script, 73 | &vec!["ARG1".to_string(), "ARG2".to_string()], 74 | options 75 | ) 76 | .unwrap(); 77 | 78 | let output = child.wait_with_output().unwrap(); 79 | 80 | assert!(output.status.success()); 81 | assert!(output.stdout.len() > 0); 82 | assert_eq!(output.stderr.len(), 0); 83 | } 84 | -------------------------------------------------------------------------------- /docs/api/search.desc/run_script/run_script-desc-0-.js: -------------------------------------------------------------------------------- 1 | searchState.loadedDescShard("run_script", 0, "run_script\nDescription text of the error reason\nRoot error\nRoot error\nCorresponds to Stdio::inherit()\nIo Options available for invoking the script\nCorresponds to Stdio::null()\nCorresponds to Stdio::pipe()\nError struct\nOptions available for invoking the script\nEnvironment environment variables to add before invocation\nSets -e flag. Will exit on any error while running the …\nDefault is IoOptions::Inherit\nDefault is IoOptions::Pipe (only pipe enables to capture …\nSets -x flag for printing each script command before …\nInvokes the provided script content and returns the …\nInvokes the provided script content and returns the …\nEnables to invoke the run_script::run function more easily …\nEnables to invoke the run_script::run_or_exit function …\nDefines the requested runner (defaults to cmd in windows …\nArgs for the runner (for cmd, /C will automatically be …\nInvokes the provided script content and returns a process …\nEnables to invoke the run_script::spawn function more …\ntypes\nThe working directory of the invocation\nDescription text of the error reason\nContains the error value\nRoot error\nRoot error\nCorresponds to Stdio::inherit()\nOptions available for IO\nCorresponds to Stdio::null()\nContains the success value\nCorresponds to Stdio::pipe()\nHolds the error information\nOptions available for invoking the script\nAlias for result with script error\nEnvironment environment variables to add before invocation\nSets -e flag. Will exit on any error while running the …\nFormats the value using the given formatter.\nReturns the argument unchanged.\nReturns the argument unchanged.\nReturns the argument unchanged.\nDefault is IoOptions::Inherit\nCalls U::from(self).\nCalls U::from(self).\nCalls U::from(self).\nReturns new instance\nDefault is IoOptions::Pipe (only pipe enables to capture …\nSets -x flag for printing each script command before …\nDefines the requested runner (defaults to cmd in windows …\nArgs for the runner (for cmd, /C will automatically be …\nThe working directory of the invocation") -------------------------------------------------------------------------------- /docs/api/search-index.js: -------------------------------------------------------------------------------- 1 | var searchIndex = new Map(JSON.parse('[["run_script",{"t":"PPPPIPPIIOOOOOHHQQOOHQCOPPPPPGPPPGFINNNNNNNNNNNNONNONNNNNNNONNNNOOOONNNNNNNNNNNNNNNNO","n":["Description","FsIOError","IOError","Inherit","IoOptions","Null","Pipe","ScriptError","ScriptOptions","env_vars","exit_on_error","input_redirection","output_redirection","print_commands","run","run_or_exit","run_script","run_script_or_exit","runner","runner_args","spawn","spawn_script","types","working_directory","Description","Err","FsIOError","IOError","Inherit","IoOptions","Null","Ok","Pipe","ScriptError","ScriptOptions","ScriptResult","borrow","","","borrow_mut","","","clone","","clone_into","","clone_to_uninit","","env_vars","eq","","exit_on_error","fmt","","","","from","","","input_redirection","into","","","new","output_redirection","print_commands","runner","runner_args","source","to_owned","","to_string","try_from","","","try_into","","","type_id","","","vzip","","","working_directory"],"q":[[0,"run_script"],[24,"run_script::types"],[85,"core::option"],[86,"alloc::string"],[87,"alloc::vec"],[88,"std::process"],[89,"core::fmt"],[90,"core::result"],[91,"core::error"],[92,"core::any"]],"i":"C`00Cb`00``b0000````00```0BbAf11h`010```2Al13010101010010330130103010000030133013013013010","f":"`````````{bd}{bf}{bh}01{{{l{j}}{l{{A`{n}}}}{l{b}}}{{Af{{Ad{Abnn}}}}}}{{{l{j}}{l{{A`{n}}}}{l{b}}}{{Ad{nn}}}}``44{{{l{j}}{l{{A`{n}}}}{l{b}}}{{Af{Ah}}}}``5````````````{l{{l{c}}}{}}00{{{l{Aj}}}{{l{Ajc}}}{}}00{{{l{Al}}}Al}{{{l{h}}}h}{{l{l{Ajc}}}An{}}0{{lB`}An}0{Ald}{{{l{Al}}{l{Al}}}f}{{{l{h}}{l{h}}}f}{Alf}{{{l{Bb}}{l{AjBd}}}{{Bh{AnBf}}}}{{{l{Bb}}{l{AjBd}}}Bj}{{{l{Al}}{l{AjBd}}}Bj}{{{l{h}}{l{AjBd}}}Bj}{cc{}}00{Alh}{{}c{}}00{{}Al}28;;{{{l{Bb}}}{{d{{l{Bl}}}}}}{lc{}}0{ln}{c{{Bh{e}}}{}{}}00{{}{{Bh{c}}}{}}00{lBn}00{{}c{}}00{Ald}","D":"Fj","p":[[8,"ScriptOptions",0],[6,"Option",85,null,1],[1,"bool"],[6,"IoOptions",24],[1,"str"],[1,"reference",null,null,1],[5,"String",86],[5,"Vec",87],[1,"i32"],[1,"tuple",null,null,1],[8,"ScriptResult",24],[5,"Child",88],[0,"mut"],[5,"ScriptOptions",24],[1,"unit"],[1,"u8"],[6,"ScriptError",24],[5,"Formatter",89],[5,"Error",89],[6,"Result",90,null,1],[8,"Result",89],[10,"Error",91],[5,"TypeId",92],[8,"ScriptError",0],[8,"IoOptions",0]],"r":[],"b":[[52,"impl-Display-for-ScriptError"],[53,"impl-Debug-for-ScriptError"]],"c":"OjAAAAAAAAA=","e":"OzAAAAEAACAABAAlAAsAMgABADYAAgBFAA8A","P":[[36,"T"],[42,""],[44,"T"],[46,""],[56,"T"],[59,""],[60,"U"],[63,""],[69,"T"],[71,""],[72,"U,T"],[75,"U"],[78,""],[81,"V"],[84,""]]}]]')); 2 | if (typeof exports !== 'undefined') exports.searchIndex = searchIndex; 3 | else if (window.initSearch) window.initSearch(searchIndex); 4 | //{"start":39,"fragment_lengths":[2473]} -------------------------------------------------------------------------------- /docs/api/settings.html: -------------------------------------------------------------------------------- 1 | Settings

Rustdoc settings

Back
-------------------------------------------------------------------------------- /docs/api/help.html: -------------------------------------------------------------------------------- 1 | Help

Rustdoc help

Back
-------------------------------------------------------------------------------- /docs/api/static.files/scrape-examples-5e967b76.js: -------------------------------------------------------------------------------- 1 | "use strict";(function(){const DEFAULT_MAX_LINES=5;const HIDDEN_MAX_LINES=10;function scrollToLoc(elt,loc,isHidden){const lines=elt.querySelectorAll("[data-nosnippet]");let scrollOffset;const maxLines=isHidden?HIDDEN_MAX_LINES:DEFAULT_MAX_LINES;if(loc[1]-loc[0]>maxLines){const line=Math.max(0,loc[0]-1);scrollOffset=lines[line].offsetTop;}else{const halfHeight=elt.offsetHeight/2;const offsetTop=lines[loc[0]].offsetTop;const lastLine=lines[loc[1]];const offsetBot=lastLine.offsetTop+lastLine.offsetHeight;const offsetMid=(offsetTop+offsetBot)/2;scrollOffset=offsetMid-halfHeight;}lines[0].parentElement.scrollTo(0,scrollOffset);elt.querySelector(".rust").scrollTo(0,scrollOffset);}function createScrapeButton(parent,className,content){const button=document.createElement("button");button.className=className;button.title=content;parent.insertBefore(button,parent.firstChild);return button;}window.updateScrapedExample=(example,buttonHolder)=>{let locIndex=0;const highlights=Array.prototype.slice.call(example.querySelectorAll(".highlight"));const link=example.querySelector(".scraped-example-title a");let expandButton=null;if(!example.classList.contains("expanded")){expandButton=createScrapeButton(buttonHolder,"expand","Show all");}const isHidden=example.parentElement.classList.contains("more-scraped-examples");const locs=example.locs;if(locs.length>1){const next=createScrapeButton(buttonHolder,"next","Next usage");const prev=createScrapeButton(buttonHolder,"prev","Previous usage");const onChangeLoc=changeIndex=>{removeClass(highlights[locIndex],"focus");changeIndex();scrollToLoc(example,locs[locIndex][0],isHidden);addClass(highlights[locIndex],"focus");const url=locs[locIndex][1];const title=locs[locIndex][2];link.href=url;link.innerHTML=title;};prev.addEventListener("click",()=>{onChangeLoc(()=>{locIndex=(locIndex-1+locs.length)%locs.length;});});next.addEventListener("click",()=>{onChangeLoc(()=>{locIndex=(locIndex+1)%locs.length;});});}if(expandButton){expandButton.addEventListener("click",()=>{if(hasClass(example,"expanded")){removeClass(example,"expanded");removeClass(expandButton,"collapse");expandButton.title="Show all";scrollToLoc(example,locs[0][0],isHidden);}else{addClass(example,"expanded");addClass(expandButton,"collapse");expandButton.title="Show single example";}});}};function setupLoc(example,isHidden){example.locs=JSON.parse(example.attributes.getNamedItem("data-locs").textContent);scrollToLoc(example,example.locs[0][0],isHidden);}const firstExamples=document.querySelectorAll(".scraped-example-list > .scraped-example");onEachLazy(firstExamples,el=>setupLoc(el,false));onEachLazy(document.querySelectorAll(".more-examples-toggle"),toggle=>{onEachLazy(toggle.querySelectorAll(".toggle-line, .hide-more"),button=>{button.addEventListener("click",()=>{toggle.open=false;});});const moreExamples=toggle.querySelectorAll(".scraped-example");toggle.querySelector("summary").addEventListener("click",()=>{setTimeout(()=>{onEachLazy(moreExamples,el=>setupLoc(el,true));});},{once:true});});})(); -------------------------------------------------------------------------------- /docs/api/static.files/COPYRIGHT-7fb11f4e.txt: -------------------------------------------------------------------------------- 1 | # REUSE-IgnoreStart 2 | 3 | These documentation pages include resources by third parties. This copyright 4 | file applies only to those resources. The following third party resources are 5 | included, and carry their own copyright notices and license terms: 6 | 7 | * Fira Sans (FiraSans-Regular.woff2, FiraSans-Medium.woff2): 8 | 9 | Copyright (c) 2014, Mozilla Foundation https://mozilla.org/ 10 | with Reserved Font Name Fira Sans. 11 | 12 | Copyright (c) 2014, Telefonica S.A. 13 | 14 | Licensed under the SIL Open Font License, Version 1.1. 15 | See FiraSans-LICENSE.txt. 16 | 17 | * rustdoc.css, main.js, and playpen.js: 18 | 19 | Copyright 2015 The Rust Developers. 20 | Licensed under the Apache License, Version 2.0 (see LICENSE-APACHE.txt) or 21 | the MIT license (LICENSE-MIT.txt) at your option. 22 | 23 | * normalize.css: 24 | 25 | Copyright (c) Nicolas Gallagher and Jonathan Neal. 26 | Licensed under the MIT license (see LICENSE-MIT.txt). 27 | 28 | * Source Code Pro (SourceCodePro-Regular.ttf.woff2, 29 | SourceCodePro-Semibold.ttf.woff2, SourceCodePro-It.ttf.woff2): 30 | 31 | Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), 32 | with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark 33 | of Adobe Systems Incorporated in the United States and/or other countries. 34 | 35 | Licensed under the SIL Open Font License, Version 1.1. 36 | See SourceCodePro-LICENSE.txt. 37 | 38 | * Source Serif 4 (SourceSerif4-Regular.ttf.woff2, SourceSerif4-Bold.ttf.woff2, 39 | SourceSerif4-It.ttf.woff2, SourceSerif4-Semibold.ttf.woff2): 40 | 41 | Copyright 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 42 | 'Source'. All Rights Reserved. Source is a trademark of Adobe in the United 43 | States and/or other countries. 44 | 45 | Licensed under the SIL Open Font License, Version 1.1. 46 | See SourceSerif4-LICENSE.md. 47 | 48 | * Nanum Barun Gothic Font (NanumBarunGothic.woff2) 49 | 50 | Copyright 2010, NAVER Corporation (http://www.nhncorp.com) 51 | with Reserved Font Name Nanum, Naver Nanum, NanumGothic, Naver NanumGothic, 52 | NanumMyeongjo, Naver NanumMyeongjo, NanumBrush, Naver NanumBrush, NanumPen, 53 | Naver NanumPen, Naver NanumGothicEco, NanumGothicEco, 54 | Naver NanumMyeongjoEco, NanumMyeongjoEco, Naver NanumGothicLight, 55 | NanumGothicLight, NanumBarunGothic, Naver NanumBarunGothic. 56 | 57 | https://hangeul.naver.com/2017/nanum 58 | https://github.com/hiun/NanumBarunGothic 59 | 60 | Licensed under the SIL Open Font License, Version 1.1. 61 | See NanumBarunGothic-LICENSE.txt. 62 | 63 | * Rust logos (rust-logo.svg, favicon.svg, favicon-32x32.png) 64 | 65 | Copyright 2025 Rust Foundation. 66 | Licensed under the Creative Commons Attribution license (CC-BY). 67 | https://rustfoundation.org/policy/rust-trademark-policy/ 68 | 69 | This copyright file is intended to be distributed with rustdoc output. 70 | 71 | # REUSE-IgnoreEnd 72 | -------------------------------------------------------------------------------- /docs/api/static.files/rust-logo-9a9549ea.svg: -------------------------------------------------------------------------------- 1 | 2 | 61 | 62 | -------------------------------------------------------------------------------- /docs/api/run_script/all.html: -------------------------------------------------------------------------------- 1 | List of all items in this crate
-------------------------------------------------------------------------------- /src/types.rs: -------------------------------------------------------------------------------- 1 | //! # types 2 | //! 3 | //! Defines the various types and aliases. 4 | //! 5 | 6 | #[cfg(test)] 7 | #[path = "./types_test.rs"] 8 | mod types_test; 9 | 10 | #[cfg(feature = "encoding_rs")] 11 | use encoding_rs::Encoding; 12 | use fsio::error::FsIOError; 13 | use std::error::Error; 14 | use std::fmt; 15 | use std::fmt::Display; 16 | use std::io; 17 | use std::path::PathBuf; 18 | 19 | /// Alias for result with script error 20 | pub type ScriptResult = Result; 21 | 22 | #[derive(Debug)] 23 | /// Holds the error information 24 | pub enum ScriptError { 25 | /// Root error 26 | IOError(io::Error), 27 | /// Root error 28 | FsIOError(FsIOError), 29 | /// Description text of the error reason 30 | Description(&'static str), 31 | } 32 | 33 | impl Display for ScriptError { 34 | /// Formats the value using the given formatter. 35 | fn fmt(&self, format: &mut fmt::Formatter) -> Result<(), fmt::Error> { 36 | match self { 37 | Self::IOError(ref cause) => cause.fmt(format), 38 | Self::FsIOError(ref cause) => cause.fmt(format), 39 | Self::Description(description) => description.fmt(format), 40 | } 41 | } 42 | } 43 | 44 | impl Error for ScriptError { 45 | fn source(&self) -> Option<&(dyn Error + 'static)> { 46 | match self { 47 | Self::Description(_) => None, 48 | Self::IOError(error) => Some(error), 49 | Self::FsIOError(error) => Some(error), 50 | } 51 | } 52 | } 53 | 54 | #[derive(Debug, Clone, PartialEq)] 55 | /// Options available for invoking the script 56 | pub struct ScriptOptions { 57 | /// Defines the requested runner (defaults to cmd in windows and sh for other platforms) 58 | pub runner: Option, 59 | /// Args for the runner (for cmd, /C will automatically be added at the end) 60 | pub runner_args: Option>, 61 | /// The working directory of the invocation 62 | pub working_directory: Option, 63 | /// Default is IoOptions::Inherit 64 | pub input_redirection: IoOptions, 65 | /// Default is IoOptions::Pipe (only pipe enables to capture the output) 66 | pub output_redirection: IoOptions, 67 | /// Sets -e flag. Will exit on any error while running the script (not available for windows) 68 | pub exit_on_error: bool, 69 | /// Sets -x flag for printing each script command before invocation (not available for windows) 70 | pub print_commands: bool, 71 | /// Environment environment variables to add before invocation 72 | pub env_vars: Option>, 73 | /// Encoding conversion for stdout and stderr 74 | #[cfg(feature = "encoding_rs")] 75 | pub encoding: Option<&'static Encoding>, 76 | } 77 | 78 | #[derive(Debug, Copy, Clone, PartialEq)] 79 | /// Options available for IO 80 | pub enum IoOptions { 81 | /// Corresponds to Stdio::null() 82 | Null, 83 | /// Corresponds to Stdio::pipe() 84 | Pipe, 85 | /// Corresponds to Stdio::inherit() 86 | Inherit, 87 | } 88 | 89 | impl ScriptOptions { 90 | /// Returns new instance 91 | pub fn new() -> ScriptOptions { 92 | ScriptOptions { 93 | runner: None, 94 | runner_args: None, 95 | working_directory: None, 96 | input_redirection: IoOptions::Inherit, 97 | output_redirection: IoOptions::Pipe, 98 | exit_on_error: false, 99 | print_commands: false, 100 | env_vars: None, 101 | #[cfg(feature = "encoding_rs")] 102 | encoding: None, 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /docs/api/static.files/src-script-813739b1.js: -------------------------------------------------------------------------------- 1 | "use strict";(function(){const rootPath=getVar("root-path");const NAME_OFFSET=0;const DIRS_OFFSET=1;const FILES_OFFSET=2;const RUSTDOC_MOBILE_BREAKPOINT=700;function closeSidebarIfMobile(){if(window.innerWidth{removeClass(document.documentElement,"src-sidebar-expanded");updateLocalStorage("source-sidebar-show","false");};window.rustdocShowSourceSidebar=()=>{addClass(document.documentElement,"src-sidebar-expanded");updateLocalStorage("source-sidebar-show","true");};window.rustdocToggleSrcSidebar=()=>{if(document.documentElement.classList.contains("src-sidebar-expanded")){window.rustdocCloseSourceSidebar();}else{window.rustdocShowSourceSidebar();}};function createSrcSidebar(srcIndexStr){const container=nonnull(document.querySelector("nav.sidebar"));const sidebar=document.createElement("div");sidebar.id="src-sidebar";const srcIndex=new Map(JSON.parse(srcIndexStr));let hasFoundFile=false;for(const[key,source]of srcIndex){source[NAME_OFFSET]=key;hasFoundFile=createDirEntry(source,sidebar,"",hasFoundFile);}container.appendChild(sidebar);const selected_elem=sidebar.getElementsByClassName("selected")[0];if(typeof selected_elem!=="undefined"){selected_elem.focus();}}function highlightSrcLines(){const match=window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);if(!match){return;}let from=parseInt(match[1],10);let to=from;if(typeof match[2]!=="undefined"){to=parseInt(match[2],10);}if(to{removeClass(e,"line-highlighted");});for(let i=from;i<=to;++i){elem=document.getElementById(""+i);if(!elem){break;}addClass(elem,"line-highlighted");}}const handleSrcHighlight=(function(){let prev_line_id=0;const set_fragment=name=>{const x=window.scrollX,y=window.scrollY;if(browserSupportsHistoryApi()){history.replaceState(null,"","#"+name);highlightSrcLines();}else{location.replace("#"+name);}window.scrollTo(x,y);};return ev=>{let cur_line_id=parseInt(ev.target.id,10);if(isNaN(cur_line_id)||ev.ctrlKey||ev.altKey||ev.metaKey){return;}ev.preventDefault();if(ev.shiftKey&&prev_line_id){if(prev_line_id>cur_line_id){const tmp=prev_line_id;prev_line_id=cur_line_id;cur_line_id=tmp;}set_fragment(prev_line_id+"-"+cur_line_id);}else{prev_line_id=cur_line_id;set_fragment(""+cur_line_id);}};}());window.addEventListener("hashchange",highlightSrcLines);onEachLazy(document.querySelectorAll("a[data-nosnippet]"),el=>{el.addEventListener("click",handleSrcHighlight);});highlightSrcLines();window.createSrcSidebar=createSrcSidebar;})(); -------------------------------------------------------------------------------- /docs/api/static.files/favicon-044be391.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /docs/api/run_script/types/index.html: -------------------------------------------------------------------------------- 1 | run_script::types - Rust

Module types

Source
Expand description

§types

2 |

Defines the various types and aliases.

3 |

Structs§

ScriptOptions
Options available for invoking the script

Enums§

IoOptions
Options available for IO
ScriptError
Holds the error information

Type Aliases§

ScriptResult
Alias for result with script error
-------------------------------------------------------------------------------- /docs/api/run_script/type.IoOptions.html: -------------------------------------------------------------------------------- 1 | IoOptions in run_script - Rust

Type Alias IoOptions

Source
pub type IoOptions = IoOptions;
Expand description

Io Options available for invoking the script

2 |

Aliased Type§

pub enum IoOptions {
3 |     Null,
4 |     Pipe,
5 |     Inherit,
6 | }

Variants§

§

Null

Corresponds to Stdio::null()

7 |
§

Pipe

Corresponds to Stdio::pipe()

8 |
§

Inherit

Corresponds to Stdio::inherit()

9 |
-------------------------------------------------------------------------------- /docs/api/run_script/types/type.ScriptResult.html: -------------------------------------------------------------------------------- 1 | ScriptResult in run_script::types - Rust

Type Alias ScriptResult

Source
pub type ScriptResult<T> = Result<T, ScriptError>;
Expand description

Alias for result with script error

2 |

Aliased Type§

pub enum ScriptResult<T> {
3 |     Ok(T),
4 |     Err(ScriptError),
5 | }

Variants§

§1.0.0

Ok(T)

Contains the success value

6 |
§1.0.0

Err(ScriptError)

Contains the error value

7 |
-------------------------------------------------------------------------------- /docs/api/static.files/FiraSans-LICENSE-05ab6dbd.txt: -------------------------------------------------------------------------------- 1 | // REUSE-IgnoreStart 2 | 3 | Digitized data copyright (c) 2012-2015, The Mozilla Foundation and Telefonica S.A. 4 | with Reserved Font Name < Fira >, 5 | 6 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 7 | This license is copied below, and is also available with a FAQ at: 8 | http://scripts.sil.org/OFL 9 | 10 | 11 | ----------------------------------------------------------- 12 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 13 | ----------------------------------------------------------- 14 | 15 | PREAMBLE 16 | The goals of the Open Font License (OFL) are to stimulate worldwide 17 | development of collaborative font projects, to support the font creation 18 | efforts of academic and linguistic communities, and to provide a free and 19 | open framework in which fonts may be shared and improved in partnership 20 | with others. 21 | 22 | The OFL allows the licensed fonts to be used, studied, modified and 23 | redistributed freely as long as they are not sold by themselves. The 24 | fonts, including any derivative works, can be bundled, embedded, 25 | redistributed and/or sold with any software provided that any reserved 26 | names are not used by derivative works. The fonts and derivatives, 27 | however, cannot be released under any other type of license. The 28 | requirement for fonts to remain under this license does not apply 29 | to any document created using the fonts or their derivatives. 30 | 31 | DEFINITIONS 32 | "Font Software" refers to the set of files released by the Copyright 33 | Holder(s) under this license and clearly marked as such. This may 34 | include source files, build scripts and documentation. 35 | 36 | "Reserved Font Name" refers to any names specified as such after the 37 | copyright statement(s). 38 | 39 | "Original Version" refers to the collection of Font Software components as 40 | distributed by the Copyright Holder(s). 41 | 42 | "Modified Version" refers to any derivative made by adding to, deleting, 43 | or substituting -- in part or in whole -- any of the components of the 44 | Original Version, by changing formats or by porting the Font Software to a 45 | new environment. 46 | 47 | "Author" refers to any designer, engineer, programmer, technical 48 | writer or other person who contributed to the Font Software. 49 | 50 | PERMISSION & CONDITIONS 51 | Permission is hereby granted, free of charge, to any person obtaining 52 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 53 | redistribute, and sell modified and unmodified copies of the Font 54 | Software, subject to the following conditions: 55 | 56 | 1) Neither the Font Software nor any of its individual components, 57 | in Original or Modified Versions, may be sold by itself. 58 | 59 | 2) Original or Modified Versions of the Font Software may be bundled, 60 | redistributed and/or sold with any software, provided that each copy 61 | contains the above copyright notice and this license. These can be 62 | included either as stand-alone text files, human-readable headers or 63 | in the appropriate machine-readable metadata fields within text or 64 | binary files as long as those fields can be easily viewed by the user. 65 | 66 | 3) No Modified Version of the Font Software may use the Reserved Font 67 | Name(s) unless explicit written permission is granted by the corresponding 68 | Copyright Holder. This restriction only applies to the primary font name as 69 | presented to the users. 70 | 71 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 72 | Software shall not be used to promote, endorse or advertise any 73 | Modified Version, except to acknowledge the contribution(s) of the 74 | Copyright Holder(s) and the Author(s) or with their explicit written 75 | permission. 76 | 77 | 5) The Font Software, modified or unmodified, in part or in whole, 78 | must be distributed entirely under this license, and must not be 79 | distributed under any other license. The requirement for fonts to 80 | remain under this license does not apply to any document created 81 | using the Font Software. 82 | 83 | TERMINATION 84 | This license becomes null and void if any of the above conditions are 85 | not met. 86 | 87 | DISCLAIMER 88 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 89 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 90 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 91 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 92 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 93 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 94 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 95 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 96 | OTHER DEALINGS IN THE FONT SOFTWARE. 97 | 98 | // REUSE-IgnoreEnd 99 | -------------------------------------------------------------------------------- /docs/api/static.files/SourceCodePro-LICENSE-67f54ca7.txt: -------------------------------------------------------------------------------- 1 | // REUSE-IgnoreStart 2 | 3 | Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries. 4 | 5 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 6 | 7 | This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL 8 | 9 | 10 | ----------------------------------------------------------- 11 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 12 | ----------------------------------------------------------- 13 | 14 | PREAMBLE 15 | The goals of the Open Font License (OFL) are to stimulate worldwide 16 | development of collaborative font projects, to support the font creation 17 | efforts of academic and linguistic communities, and to provide a free and 18 | open framework in which fonts may be shared and improved in partnership 19 | with others. 20 | 21 | The OFL allows the licensed fonts to be used, studied, modified and 22 | redistributed freely as long as they are not sold by themselves. The 23 | fonts, including any derivative works, can be bundled, embedded, 24 | redistributed and/or sold with any software provided that any reserved 25 | names are not used by derivative works. The fonts and derivatives, 26 | however, cannot be released under any other type of license. The 27 | requirement for fonts to remain under this license does not apply 28 | to any document created using the fonts or their derivatives. 29 | 30 | DEFINITIONS 31 | "Font Software" refers to the set of files released by the Copyright 32 | Holder(s) under this license and clearly marked as such. This may 33 | include source files, build scripts and documentation. 34 | 35 | "Reserved Font Name" refers to any names specified as such after the 36 | copyright statement(s). 37 | 38 | "Original Version" refers to the collection of Font Software components as 39 | distributed by the Copyright Holder(s). 40 | 41 | "Modified Version" refers to any derivative made by adding to, deleting, 42 | or substituting -- in part or in whole -- any of the components of the 43 | Original Version, by changing formats or by porting the Font Software to a 44 | new environment. 45 | 46 | "Author" refers to any designer, engineer, programmer, technical 47 | writer or other person who contributed to the Font Software. 48 | 49 | PERMISSION & CONDITIONS 50 | Permission is hereby granted, free of charge, to any person obtaining 51 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 52 | redistribute, and sell modified and unmodified copies of the Font 53 | Software, subject to the following conditions: 54 | 55 | 1) Neither the Font Software nor any of its individual components, 56 | in Original or Modified Versions, may be sold by itself. 57 | 58 | 2) Original or Modified Versions of the Font Software may be bundled, 59 | redistributed and/or sold with any software, provided that each copy 60 | contains the above copyright notice and this license. These can be 61 | included either as stand-alone text files, human-readable headers or 62 | in the appropriate machine-readable metadata fields within text or 63 | binary files as long as those fields can be easily viewed by the user. 64 | 65 | 3) No Modified Version of the Font Software may use the Reserved Font 66 | Name(s) unless explicit written permission is granted by the corresponding 67 | Copyright Holder. This restriction only applies to the primary font name as 68 | presented to the users. 69 | 70 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 71 | Software shall not be used to promote, endorse or advertise any 72 | Modified Version, except to acknowledge the contribution(s) of the 73 | Copyright Holder(s) and the Author(s) or with their explicit written 74 | permission. 75 | 76 | 5) The Font Software, modified or unmodified, in part or in whole, 77 | must be distributed entirely under this license, and must not be 78 | distributed under any other license. The requirement for fonts to 79 | remain under this license does not apply to any document created 80 | using the Font Software. 81 | 82 | TERMINATION 83 | This license becomes null and void if any of the above conditions are 84 | not met. 85 | 86 | DISCLAIMER 87 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 88 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 89 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 90 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 91 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 92 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 93 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 94 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 95 | OTHER DEALINGS IN THE FONT SOFTWARE. 96 | 97 | // REUSE-IgnoreEnd 98 | -------------------------------------------------------------------------------- /docs/api/run_script/macro.spawn_script.html: -------------------------------------------------------------------------------- 1 | spawn_script in run_script - Rust

Macro spawn_script

Source
macro_rules! spawn_script {
 2 |     ($script:expr) => { ... };
 3 |     ($script:expr, $options:expr) => { ... };
 4 |     ($script:expr, $args:expr, $options:expr) => { ... };
 5 | }
Expand description

Enables to invoke the run_script::spawn function more easily without providing all input.

6 |

§Arguments

7 |
    8 |
  • script - The script content
  • 9 |
  • args - Optional, script command line arguments. If provided, the last options argument must also be provided.
  • 10 |
  • options - Optional, options provided to the script runner
  • 11 |
12 |

§Examples


13 | use run_script::ScriptOptions;
14 | 
15 | fn main() {
16 |     // simple call to run script with only the script text
17 |     let child = run_script::spawn_script!(
18 |         r#"
19 |         echo "Test"
20 |         exit 0
21 |         "#
22 |     ).unwrap();
23 | 
24 |     // run script invoked with the script text and options
25 |     let options = ScriptOptions::new();
26 |     let child = run_script::spawn_script!(
27 |         r#"
28 |         echo "Test"
29 |         exit 0
30 |         "#,
31 |         &options
32 |     ).unwrap();
33 | 
34 |     // run script invoked with all arguments
35 |     let options = ScriptOptions::new();
36 |     let child = run_script::spawn_script!(
37 |         r#"
38 |         echo "Test"
39 |         exit 0
40 |         "#,
41 |         &vec!["ARG1".to_string(), "ARG2".to_string()],
42 |         &options
43 |     ).unwrap();
44 | }
-------------------------------------------------------------------------------- /docs/api/run_script/type.ScriptError.html: -------------------------------------------------------------------------------- 1 | ScriptError in run_script - Rust

Type Alias ScriptError

Source
pub type ScriptError = ScriptError;
Expand description

Error struct

2 |

Aliased Type§

pub enum ScriptError {
3 |     IOError(Error),
4 |     FsIOError(FsIOError),
5 |     Description(&'static str),
6 | }

Variants§

§

IOError(Error)

Root error

7 |
§

FsIOError(FsIOError)

Root error

8 |
§

Description(&'static str)

Description text of the error reason

9 |
-------------------------------------------------------------------------------- /docs/api/run_script/fn.spawn.html: -------------------------------------------------------------------------------- 1 | spawn in run_script - Rust

Function spawn

Source
pub fn spawn(
 2 |     script: &str,
 3 |     args: &Vec<String>,
 4 |     options: &ScriptOptions,
 5 | ) -> ScriptResult<Child>
Expand description

Invokes the provided script content and returns a process handle.

6 |

§Arguments

7 |
    8 |
  • script - The script content
  • 9 |
  • args - The script command line arguments
  • 10 |
  • options - Options provided to the script runner
  • 11 |
12 |

§Example

13 |
use run_script::ScriptOptions;
14 | 
15 | fn main() {
16 |     let options = ScriptOptions::new();
17 | 
18 |     let args = vec![];
19 | 
20 |     let child = run_script::spawn(
21 |         r#"
22 |         echo "Directory Info:"
23 |         dir
24 |         "#,
25 |         &args,
26 |         &options
27 |     ).unwrap();
28 | }
29 |
-------------------------------------------------------------------------------- /docs/api/static.files/SourceSerif4-LICENSE-a2cfd9d5.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Copyright 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries. 4 | Copyright 2014 - 2023 Adobe (http://www.adobe.com/), with Reserved Font Name ‘Source’. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries. 5 | 6 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 7 | 8 | This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL 9 | 10 | 11 | ----------------------------------------------------------- 12 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 13 | ----------------------------------------------------------- 14 | 15 | PREAMBLE 16 | The goals of the Open Font License (OFL) are to stimulate worldwide 17 | development of collaborative font projects, to support the font creation 18 | efforts of academic and linguistic communities, and to provide a free and 19 | open framework in which fonts may be shared and improved in partnership 20 | with others. 21 | 22 | The OFL allows the licensed fonts to be used, studied, modified and 23 | redistributed freely as long as they are not sold by themselves. The 24 | fonts, including any derivative works, can be bundled, embedded, 25 | redistributed and/or sold with any software provided that any reserved 26 | names are not used by derivative works. The fonts and derivatives, 27 | however, cannot be released under any other type of license. The 28 | requirement for fonts to remain under this license does not apply 29 | to any document created using the fonts or their derivatives. 30 | 31 | DEFINITIONS 32 | "Font Software" refers to the set of files released by the Copyright 33 | Holder(s) under this license and clearly marked as such. This may 34 | include source files, build scripts and documentation. 35 | 36 | "Reserved Font Name" refers to any names specified as such after the 37 | copyright statement(s). 38 | 39 | "Original Version" refers to the collection of Font Software components as 40 | distributed by the Copyright Holder(s). 41 | 42 | "Modified Version" refers to any derivative made by adding to, deleting, 43 | or substituting -- in part or in whole -- any of the components of the 44 | Original Version, by changing formats or by porting the Font Software to a 45 | new environment. 46 | 47 | "Author" refers to any designer, engineer, programmer, technical 48 | writer or other person who contributed to the Font Software. 49 | 50 | PERMISSION & CONDITIONS 51 | Permission is hereby granted, free of charge, to any person obtaining 52 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 53 | redistribute, and sell modified and unmodified copies of the Font 54 | Software, subject to the following conditions: 55 | 56 | 1) Neither the Font Software nor any of its individual components, 57 | in Original or Modified Versions, may be sold by itself. 58 | 59 | 2) Original or Modified Versions of the Font Software may be bundled, 60 | redistributed and/or sold with any software, provided that each copy 61 | contains the above copyright notice and this license. These can be 62 | included either as stand-alone text files, human-readable headers or 63 | in the appropriate machine-readable metadata fields within text or 64 | binary files as long as those fields can be easily viewed by the user. 65 | 66 | 3) No Modified Version of the Font Software may use the Reserved Font 67 | Name(s) unless explicit written permission is granted by the corresponding 68 | Copyright Holder. This restriction only applies to the primary font name as 69 | presented to the users. 70 | 71 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 72 | Software shall not be used to promote, endorse or advertise any 73 | Modified Version, except to acknowledge the contribution(s) of the 74 | Copyright Holder(s) and the Author(s) or with their explicit written 75 | permission. 76 | 77 | 5) The Font Software, modified or unmodified, in part or in whole, 78 | must be distributed entirely under this license, and must not be 79 | distributed under any other license. The requirement for fonts to 80 | remain under this license does not apply to any document created 81 | using the Font Software. 82 | 83 | TERMINATION 84 | This license becomes null and void if any of the above conditions are 85 | not met. 86 | 87 | DISCLAIMER 88 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 89 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 90 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 91 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 92 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 93 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 94 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 95 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 96 | OTHER DEALINGS IN THE FONT SOFTWARE. 97 | 98 | 99 | -------------------------------------------------------------------------------- /docs/api/static.files/NanumBarunGothic-LICENSE-a37d393b.txt: -------------------------------------------------------------------------------- 1 | // REUSE-IgnoreStart 2 | 3 | Copyright (c) 2010, NAVER Corporation (https://www.navercorp.com/), 4 | 5 | with Reserved Font Name Nanum, Naver Nanum, NanumGothic, Naver NanumGothic, 6 | NanumMyeongjo, Naver NanumMyeongjo, NanumBrush, Naver NanumBrush, NanumPen, 7 | Naver NanumPen, Naver NanumGothicEco, NanumGothicEco, Naver NanumMyeongjoEco, 8 | NanumMyeongjoEco, Naver NanumGothicLight, NanumGothicLight, NanumBarunGothic, 9 | Naver NanumBarunGothic, NanumSquareRound, NanumBarunPen, MaruBuri 10 | 11 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 12 | This license is copied below, and is also available with a FAQ at: 13 | http://scripts.sil.org/OFL 14 | 15 | 16 | ----------------------------------------------------------- 17 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 18 | ----------------------------------------------------------- 19 | 20 | PREAMBLE 21 | The goals of the Open Font License (OFL) are to stimulate worldwide 22 | development of collaborative font projects, to support the font creation 23 | efforts of academic and linguistic communities, and to provide a free and 24 | open framework in which fonts may be shared and improved in partnership 25 | with others. 26 | 27 | The OFL allows the licensed fonts to be used, studied, modified and 28 | redistributed freely as long as they are not sold by themselves. The 29 | fonts, including any derivative works, can be bundled, embedded, 30 | redistributed and/or sold with any software provided that any reserved 31 | names are not used by derivative works. The fonts and derivatives, 32 | however, cannot be released under any other type of license. The 33 | requirement for fonts to remain under this license does not apply 34 | to any document created using the fonts or their derivatives. 35 | 36 | DEFINITIONS 37 | "Font Software" refers to the set of files released by the Copyright 38 | Holder(s) under this license and clearly marked as such. This may 39 | include source files, build scripts and documentation. 40 | 41 | "Reserved Font Name" refers to any names specified as such after the 42 | copyright statement(s). 43 | 44 | "Original Version" refers to the collection of Font Software components as 45 | distributed by the Copyright Holder(s). 46 | 47 | "Modified Version" refers to any derivative made by adding to, deleting, 48 | or substituting -- in part or in whole -- any of the components of the 49 | Original Version, by changing formats or by porting the Font Software to a 50 | new environment. 51 | 52 | "Author" refers to any designer, engineer, programmer, technical 53 | writer or other person who contributed to the Font Software. 54 | 55 | PERMISSION & CONDITIONS 56 | Permission is hereby granted, free of charge, to any person obtaining 57 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 58 | redistribute, and sell modified and unmodified copies of the Font 59 | Software, subject to the following conditions: 60 | 61 | 1) Neither the Font Software nor any of its individual components, 62 | in Original or Modified Versions, may be sold by itself. 63 | 64 | 2) Original or Modified Versions of the Font Software may be bundled, 65 | redistributed and/or sold with any software, provided that each copy 66 | contains the above copyright notice and this license. These can be 67 | included either as stand-alone text files, human-readable headers or 68 | in the appropriate machine-readable metadata fields within text or 69 | binary files as long as those fields can be easily viewed by the user. 70 | 71 | 3) No Modified Version of the Font Software may use the Reserved Font 72 | Name(s) unless explicit written permission is granted by the corresponding 73 | Copyright Holder. This restriction only applies to the primary font name as 74 | presented to the users. 75 | 76 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 77 | Software shall not be used to promote, endorse or advertise any 78 | Modified Version, except to acknowledge the contribution(s) of the 79 | Copyright Holder(s) and the Author(s) or with their explicit written 80 | permission. 81 | 82 | 5) The Font Software, modified or unmodified, in part or in whole, 83 | must be distributed entirely under this license, and must not be 84 | distributed under any other license. The requirement for fonts to 85 | remain under this license does not apply to any document created 86 | using the Font Software. 87 | 88 | TERMINATION 89 | This license becomes null and void if any of the above conditions are 90 | not met. 91 | 92 | DISCLAIMER 93 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 94 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 95 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 96 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 97 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 98 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 99 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 100 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 101 | OTHER DEALINGS IN THE FONT SOFTWARE. 102 | 103 | // REUSE-IgnoreEnd 104 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # run_script 2 | 3 | [![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)
4 | [![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)
5 | [![Built with cargo-make](https://sagiegurari.github.io/cargo-make/assets/badges/cargo-make.svg)](https://sagiegurari.github.io/cargo-make) 6 | 7 | > Run shell scripts in [rust](https://www.rust-lang.org/). 8 | 9 | * [Overview](#overview) 10 | * [Usage](#usage) 11 | * [Installation](#installation) 12 | * [API Documentation](https://sagiegurari.github.io/run_script/) 13 | * [Contributing](.github/CONTRIBUTING.md) 14 | * [Release History](CHANGELOG.md) 15 | * [License](#license) 16 | 17 | 18 | ## Overview 19 | This library enables to invoke shell scripts based on their content.
20 | While std::process::Command works great to execute standalone command, you need more manual code to take a script text and execute it.
21 | For this purpose, this library was created. 22 | 23 | 24 | ## Usage 25 | Simply include the library and invoke the run/spawn function with the script text and run options: 26 | 27 | 28 | ```rust 29 | use run_script::ScriptOptions; 30 | 31 | fn main() { 32 | let options = ScriptOptions::new(); 33 | 34 | let args = vec![]; 35 | 36 | // run the script and get the script execution output 37 | let (code, output, error) = run_script::run( 38 | r#" 39 | echo "Directory Info:" 40 | dir 41 | "#, 42 | &args, 43 | &options, 44 | ) 45 | .unwrap(); 46 | 47 | println!("Exit Code: {}", code); 48 | println!("Output: {}", output); 49 | println!("Error: {}", error); 50 | 51 | // run the script and get a handle to the running child process 52 | let child = run_script::spawn( 53 | r#" 54 | echo "Directory Info:" 55 | dir 56 | "#, 57 | &args, 58 | &options, 59 | ) 60 | .unwrap(); 61 | 62 | let spawn_output = child.wait_with_output().unwrap(); 63 | 64 | println!("Success: {}", &spawn_output.status.success()); 65 | } 66 | ``` 67 | 68 | 69 | The library also provides the **run_script!**, **spawn_script!** and **run_script_or_exit!** macros for simpler usage. 70 | 71 | 72 | ```rust 73 | use run_script::ScriptOptions; 74 | 75 | fn main() { 76 | // simple call to run script with only the script text 77 | let (code, output, error) = run_script::run_script!( 78 | r#" 79 | echo "Test" 80 | exit 0 81 | "# 82 | ) 83 | .unwrap(); 84 | 85 | println!("Exit Code: {}", code); 86 | println!("Output: {}", output); 87 | println!("Error: {}", error); 88 | 89 | // run script invoked with the script text and options 90 | let options = ScriptOptions::new(); 91 | let (code, output, error) = run_script::run_script!( 92 | r#" 93 | echo "Test" 94 | exit 0 95 | "#, 96 | &options 97 | ) 98 | .unwrap(); 99 | 100 | println!("Exit Code: {}", code); 101 | println!("Output: {}", output); 102 | println!("Error: {}", error); 103 | 104 | // run script invoked with all arguments 105 | let options = ScriptOptions::new(); 106 | let (code, output, error) = run_script::run_script!( 107 | r#" 108 | echo "Test" 109 | exit 0 110 | "#, 111 | &vec!["ARG1".to_string(), "ARG2".to_string()], 112 | &options 113 | ) 114 | .unwrap(); 115 | 116 | println!("Exit Code: {}", code); 117 | println!("Output: {}", output); 118 | println!("Error: {}", error); 119 | 120 | // spawn_script! works the same as run_script! but returns the child process handle 121 | let child = run_script::spawn_script!( 122 | r#" 123 | echo "Test" 124 | exit 0 125 | "# 126 | ) 127 | .unwrap(); 128 | 129 | println!("PID: {}", child.id()); 130 | } 131 | ``` 132 | 133 | 134 | 135 | ## Installation 136 | In order to use this library, just add it as a dependency: 137 | 138 | ```ini 139 | [dependencies] 140 | run_script = "^0.11.2" 141 | ``` 142 | 143 | ## API Documentation 144 | See full docs at: [API Docs](https://sagiegurari.github.io/run_script/) 145 | 146 | ## Contributing 147 | See [contributing guide](.github/CONTRIBUTING.md) 148 | 149 | 150 | ## Release History 151 | 152 | See [Changelog](CHANGELOG.md) 153 | 154 | 155 | ## License 156 | Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license. 157 | -------------------------------------------------------------------------------- /docs/api/run_script/fn.run_or_exit.html: -------------------------------------------------------------------------------- 1 | run_or_exit in run_script - Rust

Function run_or_exit

Source
pub fn run_or_exit(
 2 |     script: &str,
 3 |     args: &Vec<String>,
 4 |     options: &ScriptOptions,
 5 | ) -> (String, String)
Expand description

Invokes the provided script content and returns the invocation output. 6 | In case of invocation error or error exit code, this function will exit the main process.

7 |

§Arguments

8 |
    9 |
  • script - The script content
  • 10 |
  • args - The script command line arguments
  • 11 |
  • options - Options provided to the script runner
  • 12 |
13 |

§Example

14 |
use run_script::ScriptOptions;
15 | 
16 | fn main() {
17 |     let options = ScriptOptions::new();
18 | 
19 |     let args = vec![];
20 | 
21 |     let (output, error) = run_script::run_or_exit(
22 |         r#"
23 |         echo "Hello World"
24 |         "#,
25 |         &args,
26 |         &options
27 |     );
28 | 
29 |     println!("Output: {}", output);
30 |     println!("Error: {}", error);
31 | }
32 |
-------------------------------------------------------------------------------- /docs/api/run_script/macro.run_script.html: -------------------------------------------------------------------------------- 1 | run_script in run_script - Rust

Macro run_script

Source
macro_rules! run_script {
 2 |     ($script:expr) => { ... };
 3 |     ($script:expr, $options:expr) => { ... };
 4 |     ($script:expr, $args:expr, $options:expr) => { ... };
 5 | }
Expand description

Enables to invoke the run_script::run function more easily without providing all input.

6 |

§Arguments

7 |
    8 |
  • script - The script content
  • 9 |
  • args - Optional, script command line arguments. If provided, the last options argument must also be provided.
  • 10 |
  • options - Optional, options provided to the script runner
  • 11 |
12 |

§Examples

13 |
use run_script::ScriptOptions;
14 | 
15 | fn main() {
16 |     // simple call to run script with only the script text
17 |     let (code, output, error) = run_script::run_script!(
18 |         r#"
19 |         echo "Test"
20 |         exit 0
21 |         "#
22 |     ).unwrap();
23 | 
24 |     // run script invoked with the script text and options
25 |     let options = ScriptOptions::new();
26 |     let (code, output, error) = run_script::run_script!(
27 |         r#"
28 |         echo "Test"
29 |         exit 0
30 |         "#,
31 |         &options
32 |     ).unwrap();
33 | 
34 |     // run script invoked with all arguments
35 |     let options = ScriptOptions::new();
36 |     let (code, output, error) = run_script::run_script!(
37 |         r#"
38 |         echo "Test"
39 |         exit 0
40 |         "#,
41 |         &vec!["ARG1".to_string(), "ARG2".to_string()],
42 |         &options
43 |     ).unwrap();
44 | }
45 |
-------------------------------------------------------------------------------- /docs/api/run_script/macro.run_script_or_exit.html: -------------------------------------------------------------------------------- 1 | run_script_or_exit in run_script - Rust

Macro run_script_or_exit

Source
macro_rules! run_script_or_exit {
 2 |     ($script:expr) => { ... };
 3 |     ($script:expr, $options:expr) => { ... };
 4 |     ($script:expr, $args:expr, $options:expr) => { ... };
 5 | }
Expand description

Enables to invoke the run_script::run_or_exit function more easily without providing all input.

6 |

§Arguments

7 |
    8 |
  • script - The script content
  • 9 |
  • args - Optional, script command line arguments. If provided, the last options argument must also be provided.
  • 10 |
  • options - Optional, options provided to the script runner
  • 11 |
12 |

§Examples

13 |
use run_script::ScriptOptions;
14 | 
15 | fn main() {
16 |     // simple call to the macro with only the script text
17 |     let (output, error) = run_script::run_script_or_exit!(
18 |         r#"
19 |         echo "Test"
20 |         exit 0
21 |         "#
22 |     );
23 | 
24 |     // macro invoked with the script text and options
25 |     let options = ScriptOptions::new();
26 |     let (output, error) = run_script::run_script_or_exit!(
27 |         r#"
28 |         echo "Test"
29 |         exit 0
30 |         "#,
31 |         &options
32 |     );
33 | 
34 |     // macro invoked with all arguments
35 |     let options = ScriptOptions::new();
36 |     let (output, error) = run_script::run_script_or_exit!(
37 |         r#"
38 |         echo "Test"
39 |         exit 0
40 |         "#,
41 |         &vec!["ARG1".to_string(), "ARG2".to_string()],
42 |         &options
43 |     );
44 | }
45 |
-------------------------------------------------------------------------------- /docs/api/run_script/fn.run.html: -------------------------------------------------------------------------------- 1 | run in run_script - Rust

Function run

Source
pub fn run(
 2 |     script: &str,
 3 |     args: &Vec<String>,
 4 |     options: &ScriptOptions,
 5 | ) -> ScriptResult<(i32, String, String)>
Expand description

Invokes the provided script content and returns the invocation output.

6 |

§Arguments

7 |
    8 |
  • script - The script content
  • 9 |
  • args - The script command line arguments
  • 10 |
  • options - Options provided to the script runner
  • 11 |
12 |

§Example

13 |
use run_script::ScriptOptions;
14 | 
15 | fn main() {
16 |     let options = ScriptOptions::new();
17 | 
18 |     let args = vec![];
19 | 
20 |     let (code, output, error) = run_script::run(
21 |         r#"
22 |         echo "Directory Info:"
23 |         dir
24 |         "#,
25 |         &args,
26 |         &options
27 |     ).unwrap();
28 | 
29 |     println!("Exit Code: {}", code);
30 |     println!("Output: {}", output);
31 |     println!("Error: {}", error);
32 | }
33 |
-------------------------------------------------------------------------------- /src/macros.rs: -------------------------------------------------------------------------------- 1 | //! # macros 2 | //! 3 | //! Defines the library macros 4 | //! 5 | 6 | /// Enables to invoke the run_script::run function more easily without providing all input. 7 | /// 8 | /// # Arguments 9 | /// 10 | /// * `script` - The script content 11 | /// * `args` - Optional, script command line arguments. If provided, the last options argument must also be provided. 12 | /// * `options` - Optional, options provided to the script runner 13 | /// 14 | /// # Examples 15 | /// 16 | /// ```rust 17 | /// use run_script::ScriptOptions; 18 | /// 19 | /// fn main() { 20 | /// // simple call to run script with only the script text 21 | /// let (code, output, error) = run_script::run_script!( 22 | /// r#" 23 | /// echo "Test" 24 | /// exit 0 25 | /// "# 26 | /// ).unwrap(); 27 | /// 28 | /// // run script invoked with the script text and options 29 | /// let options = ScriptOptions::new(); 30 | /// let (code, output, error) = run_script::run_script!( 31 | /// r#" 32 | /// echo "Test" 33 | /// exit 0 34 | /// "#, 35 | /// &options 36 | /// ).unwrap(); 37 | /// 38 | /// // run script invoked with all arguments 39 | /// let options = ScriptOptions::new(); 40 | /// let (code, output, error) = run_script::run_script!( 41 | /// r#" 42 | /// echo "Test" 43 | /// exit 0 44 | /// "#, 45 | /// &vec!["ARG1".to_string(), "ARG2".to_string()], 46 | /// &options 47 | /// ).unwrap(); 48 | /// } 49 | /// ``` 50 | #[macro_export] 51 | macro_rules! run_script { 52 | ($script:expr) => {{ 53 | let args = vec![]; 54 | let options = $crate::ScriptOptions::new(); 55 | $crate::run(&$script, &args, &options) 56 | }}; 57 | ($script:expr, $options:expr) => {{ 58 | let args = vec![]; 59 | $crate::run(&$script, &args, &$options) 60 | }}; 61 | ($script:expr, $args:expr, $options:expr) => {{ 62 | $crate::run(&$script, &$args, &$options) 63 | }}; 64 | } 65 | 66 | /// Enables to invoke the run_script::spawn function more easily without providing all input. 67 | /// 68 | /// # Arguments 69 | /// 70 | /// * `script` - The script content 71 | /// * `args` - Optional, script command line arguments. If provided, the last options argument must also be provided. 72 | /// * `options` - Optional, options provided to the script runner 73 | /// 74 | /// # Examples 75 | /// 76 | /// ```rust_script; 77 | /// 78 | /// use run_script::ScriptOptions; 79 | /// 80 | /// fn main() { 81 | /// // simple call to run script with only the script text 82 | /// let child = run_script::spawn_script!( 83 | /// r#" 84 | /// echo "Test" 85 | /// exit 0 86 | /// "# 87 | /// ).unwrap(); 88 | /// 89 | /// // run script invoked with the script text and options 90 | /// let options = ScriptOptions::new(); 91 | /// let child = run_script::spawn_script!( 92 | /// r#" 93 | /// echo "Test" 94 | /// exit 0 95 | /// "#, 96 | /// &options 97 | /// ).unwrap(); 98 | /// 99 | /// // run script invoked with all arguments 100 | /// let options = ScriptOptions::new(); 101 | /// let child = run_script::spawn_script!( 102 | /// r#" 103 | /// echo "Test" 104 | /// exit 0 105 | /// "#, 106 | /// &vec!["ARG1".to_string(), "ARG2".to_string()], 107 | /// &options 108 | /// ).unwrap(); 109 | /// } 110 | /// ``` 111 | #[macro_export] 112 | macro_rules! spawn_script { 113 | ($script:expr) => {{ 114 | let args = vec![]; 115 | let options = $crate::ScriptOptions::new(); 116 | $crate::spawn(&$script, &args, &options) 117 | }}; 118 | ($script:expr, $options:expr) => {{ 119 | let args = vec![]; 120 | $crate::spawn(&$script, &args, &$options) 121 | }}; 122 | ($script:expr, $args:expr, $options:expr) => {{ 123 | $crate::spawn(&$script, &$args, &$options) 124 | }}; 125 | } 126 | 127 | /// Enables to invoke the run_script::run_or_exit function more easily without providing all input. 128 | /// 129 | /// # Arguments 130 | /// 131 | /// * `script` - The script content 132 | /// * `args` - Optional, script command line arguments. If provided, the last options argument must also be provided. 133 | /// * `options` - Optional, options provided to the script runner 134 | /// 135 | /// # Examples 136 | /// 137 | /// ```rust 138 | /// use run_script::ScriptOptions; 139 | /// 140 | /// fn main() { 141 | /// // simple call to the macro with only the script text 142 | /// let (output, error) = run_script::run_script_or_exit!( 143 | /// r#" 144 | /// echo "Test" 145 | /// exit 0 146 | /// "# 147 | /// ); 148 | /// 149 | /// // macro invoked with the script text and options 150 | /// let options = ScriptOptions::new(); 151 | /// let (output, error) = run_script::run_script_or_exit!( 152 | /// r#" 153 | /// echo "Test" 154 | /// exit 0 155 | /// "#, 156 | /// &options 157 | /// ); 158 | /// 159 | /// // macro invoked with all arguments 160 | /// let options = ScriptOptions::new(); 161 | /// let (output, error) = run_script::run_script_or_exit!( 162 | /// r#" 163 | /// echo "Test" 164 | /// exit 0 165 | /// "#, 166 | /// &vec!["ARG1".to_string(), "ARG2".to_string()], 167 | /// &options 168 | /// ); 169 | /// } 170 | /// ``` 171 | #[macro_export] 172 | macro_rules! run_script_or_exit { 173 | ($script:expr) => {{ 174 | let args = vec![]; 175 | let options = $crate::ScriptOptions::new(); 176 | $crate::run_or_exit(&$script, &args, &options) 177 | }}; 178 | ($script:expr, $options:expr) => {{ 179 | let args = vec![]; 180 | $crate::run_or_exit(&$script, &args, &$options) 181 | }}; 182 | ($script:expr, $args:expr, $options:expr) => {{ 183 | $crate::run_or_exit(&$script, &$args, &$options) 184 | }}; 185 | } 186 | -------------------------------------------------------------------------------- /docs/api/static.files/storage-68b7e25d.js: -------------------------------------------------------------------------------- 1 | "use strict";const builtinThemes=["light","dark","ayu"];const darkThemes=["dark","ayu"];window.currentTheme=(function(){const currentTheme=document.getElementById("themeStyle");return currentTheme instanceof HTMLLinkElement?currentTheme:null;})();const settingsDataset=(function(){const settingsElement=document.getElementById("default-settings");return settingsElement&&settingsElement.dataset?settingsElement.dataset:null;})();function nonnull(x,msg){if(x===null){throw(msg||"unexpected null value!");}else{return x;}}function nonundef(x,msg){if(x===undefined){throw(msg||"unexpected null value!");}else{return x;}}function getSettingValue(settingName){const current=getCurrentValue(settingName);if(current===null&&settingsDataset!==null){const def=settingsDataset[settingName.replace(/-/g,"_")];if(def!==undefined){return def;}}return current;}const localStoredTheme=getSettingValue("theme");function hasClass(elem,className){return!!elem&&!!elem.classList&&elem.classList.contains(className);}function addClass(elem,className){if(elem&&elem.classList){elem.classList.add(className);}}function removeClass(elem,className){if(elem&&elem.classList){elem.classList.remove(className);}}function onEach(arr,func){for(const elem of arr){if(func(elem)){return true;}}return false;}function onEachLazy(lazyArray,func){return onEach(Array.prototype.slice.call(lazyArray),func);}function updateLocalStorage(name,value){try{if(value===null){window.localStorage.removeItem("rustdoc-"+name);}else{window.localStorage.setItem("rustdoc-"+name,value);}}catch(e){}}function getCurrentValue(name){try{return window.localStorage.getItem("rustdoc-"+name);}catch(e){return null;}}function getVar(name){const el=document.querySelector("head > meta[name='rustdoc-vars']");return el?el.getAttribute("data-"+name):null;}function switchTheme(newThemeName,saveTheme){const themeNames=(getVar("themes")||"").split(",").filter(t=>t);themeNames.push(...builtinThemes);if(newThemeName===null||themeNames.indexOf(newThemeName)===-1){return;}if(saveTheme){updateLocalStorage("theme",newThemeName);}document.documentElement.setAttribute("data-theme",newThemeName);if(builtinThemes.indexOf(newThemeName)!==-1){if(window.currentTheme&&window.currentTheme.parentNode){window.currentTheme.parentNode.removeChild(window.currentTheme);window.currentTheme=null;}}else{const newHref=getVar("root-path")+encodeURIComponent(newThemeName)+getVar("resource-suffix")+".css";if(!window.currentTheme){if(document.readyState==="loading"){document.write(``);window.currentTheme=(function(){const currentTheme=document.getElementById("themeStyle");return currentTheme instanceof HTMLLinkElement?currentTheme:null;})();}else{window.currentTheme=document.createElement("link");window.currentTheme.rel="stylesheet";window.currentTheme.id="themeStyle";window.currentTheme.href=newHref;document.documentElement.appendChild(window.currentTheme);}}else if(newHref!==window.currentTheme.href){window.currentTheme.href=newHref;}}}const updateTheme=(function(){const mql=window.matchMedia("(prefers-color-scheme: dark)");function updateTheme(){if(getSettingValue("use-system-theme")!=="false"){const lightTheme=getSettingValue("preferred-light-theme")||"light";const darkTheme=getSettingValue("preferred-dark-theme")||"dark";updateLocalStorage("use-system-theme","true");switchTheme(mql.matches?darkTheme:lightTheme,true);}else{switchTheme(getSettingValue("theme"),false);}}mql.addEventListener("change",updateTheme);return updateTheme;})();if(getSettingValue("use-system-theme")!=="false"&&window.matchMedia){if(getSettingValue("use-system-theme")===null&&getSettingValue("preferred-dark-theme")===null&&localStoredTheme!==null&&darkThemes.indexOf(localStoredTheme)>=0){updateLocalStorage("preferred-dark-theme",localStoredTheme);}}updateTheme();if(getSettingValue("source-sidebar-show")==="true"){addClass(document.documentElement,"src-sidebar-expanded");}if(getSettingValue("hide-sidebar")==="true"){addClass(document.documentElement,"hide-sidebar");}if(getSettingValue("hide-toc")==="true"){addClass(document.documentElement,"hide-toc");}if(getSettingValue("hide-modnav")==="true"){addClass(document.documentElement,"hide-modnav");}if(getSettingValue("sans-serif-fonts")==="true"){addClass(document.documentElement,"sans-serif");}if(getSettingValue("word-wrap-source-code")==="true"){addClass(document.documentElement,"word-wrap-source-code");}function updateSidebarWidth(){const desktopSidebarWidth=getSettingValue("desktop-sidebar-width");if(desktopSidebarWidth&&desktopSidebarWidth!=="null"){document.documentElement.style.setProperty("--desktop-sidebar-width",desktopSidebarWidth+"px",);}const srcSidebarWidth=getSettingValue("src-sidebar-width");if(srcSidebarWidth&&srcSidebarWidth!=="null"){document.documentElement.style.setProperty("--src-sidebar-width",srcSidebarWidth+"px",);}}updateSidebarWidth();window.addEventListener("pageshow",ev=>{if(ev.persisted){setTimeout(updateTheme,0);setTimeout(updateSidebarWidth,0);}});class RustdocSearchElement extends HTMLElement{constructor(){super();}connectedCallback(){const rootPath=getVar("root-path");const currentCrate=getVar("current-crate");this.innerHTML=``;}}window.customElements.define("rustdoc-search",RustdocSearchElement);class RustdocToolbarElement extends HTMLElement{constructor(){super();}connectedCallback(){if(this.firstElementChild){return;}const rootPath=getVar("root-path");this.innerHTML=` 17 |
18 | Settings 19 |
20 |
21 | Help 22 |
23 | `;}}window.customElements.define("rustdoc-toolbar",RustdocToolbarElement); -------------------------------------------------------------------------------- /docs/api/type.impl/run_script/types/enum.IoOptions.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var type_impls = Object.fromEntries([["run_script",[["
Source§

impl Clone for IoOptions

Source§

fn clone(&self) -> IoOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
","Clone","run_script::IoOptions"],["
Source§

impl Debug for IoOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
","Debug","run_script::IoOptions"],["
Source§

impl PartialEq for IoOptions

Source§

fn eq(&self, other: &IoOptions) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient,\nand should not be overridden without very good reason.
","PartialEq","run_script::IoOptions"],["
Source§

impl Copy for IoOptions

","Copy","run_script::IoOptions"],["
Source§

impl StructuralPartialEq for IoOptions

","StructuralPartialEq","run_script::IoOptions"]]]]); 3 | if (window.register_type_impls) { 4 | window.register_type_impls(type_impls); 5 | } else { 6 | window.pending_type_impls = type_impls; 7 | } 8 | })() 9 | //{"start":55,"fragment_lengths":[7225]} -------------------------------------------------------------------------------- /docs/api/static.files/settings-5514c975.js: -------------------------------------------------------------------------------- 1 | "use strict";(function(){const isSettingsPage=window.location.pathname.endsWith("/settings.html");function elemContainsTarget(elem,target){if(target instanceof Node){return elem.contains(target);}else{return false;}}function changeSetting(settingName,value){if(settingName==="theme"){const useSystem=value==="system preference"?"true":"false";updateLocalStorage("use-system-theme",useSystem);}updateLocalStorage(settingName,""+value);switch(settingName){case"theme":case"preferred-dark-theme":case"preferred-light-theme":updateTheme();updateLightAndDark();break;case"line-numbers":if(value===true){const f=window.rustdoc_add_line_numbers_to_examples;if(f!==undefined){f();}}else{const f=window.rustdoc_remove_line_numbers_from_examples;if(f!==undefined){f();}}break;case"hide-sidebar":if(value===true){addClass(document.documentElement,"hide-sidebar");}else{removeClass(document.documentElement,"hide-sidebar");}break;case"hide-toc":if(value===true){addClass(document.documentElement,"hide-toc");}else{removeClass(document.documentElement,"hide-toc");}break;case"hide-modnav":if(value===true){addClass(document.documentElement,"hide-modnav");}else{removeClass(document.documentElement,"hide-modnav");}break;case"sans-serif-fonts":if(value===true){addClass(document.documentElement,"sans-serif");}else{removeClass(document.documentElement,"sans-serif");}break;case"word-wrap-source-code":if(value===true){addClass(document.documentElement,"word-wrap-source-code");}else{removeClass(document.documentElement,"word-wrap-source-code");}break;}}function showLightAndDark(){removeClass(document.getElementById("preferred-light-theme"),"hidden");removeClass(document.getElementById("preferred-dark-theme"),"hidden");}function hideLightAndDark(){addClass(document.getElementById("preferred-light-theme"),"hidden");addClass(document.getElementById("preferred-dark-theme"),"hidden");}function updateLightAndDark(){const useSystem=getSettingValue("use-system-theme");if(useSystem==="true"||(useSystem===null&&getSettingValue("theme")===null)){showLightAndDark();}else{hideLightAndDark();}}function setEvents(settingsElement){updateLightAndDark();onEachLazy(settingsElement.querySelectorAll("input[type=\"checkbox\"]"),toggle=>{const settingId=toggle.id;const settingValue=getSettingValue(settingId);if(settingValue!==null){toggle.checked=settingValue==="true";}toggle.onchange=()=>{changeSetting(toggle.id,toggle.checked);};});onEachLazy(settingsElement.querySelectorAll("input[type=\"radio\"]"),elem=>{const settingId=elem.name;let settingValue=getSettingValue(settingId);if(settingId==="theme"){const useSystem=getSettingValue("use-system-theme");if(useSystem==="true"||settingValue===null){settingValue=useSystem==="false"?"light":"system preference";}}if(settingValue!==null&&settingValue!=="null"){elem.checked=settingValue===elem.value;}elem.addEventListener("change",()=>{changeSetting(elem.name,elem.value);});},);}function buildSettingsPageSections(settings){let output="";for(const setting of settings){const js_data_name=setting["js_name"];const setting_name=setting["name"];if(setting["options"]!==undefined){output+=`\ 2 |
3 |
${setting_name}
4 |
`;onEach(setting["options"],option=>{const checked=option===setting["default"]?" checked":"";const full=`${js_data_name}-${option.replace(/ /g,"-")}`;output+=`\ 5 | `;});output+=`\ 10 |
11 |
`;}else{const checked=setting["default"]===true?" checked":"";output+=`\ 12 |
\ 13 | \ 17 |
`;}}return output;}function buildSettingsPage(){const theme_list=getVar("themes");const theme_names=(theme_list===null?"":theme_list).split(",").filter(t=>t);theme_names.push("light","dark","ayu");const settings=[{"name":"Theme","js_name":"theme","default":"system preference","options":theme_names.concat("system preference"),},{"name":"Preferred light theme","js_name":"preferred-light-theme","default":"light","options":theme_names,},{"name":"Preferred dark theme","js_name":"preferred-dark-theme","default":"dark","options":theme_names,},{"name":"Auto-hide item contents for large items","js_name":"auto-hide-large-items","default":true,},{"name":"Auto-hide item methods' documentation","js_name":"auto-hide-method-docs","default":false,},{"name":"Auto-hide trait implementation documentation","js_name":"auto-hide-trait-implementations","default":false,},{"name":"Directly go to item in search if there is only one result","js_name":"go-to-only-result","default":false,},{"name":"Show line numbers on code examples","js_name":"line-numbers","default":false,},{"name":"Hide persistent navigation bar","js_name":"hide-sidebar","default":false,},{"name":"Hide table of contents","js_name":"hide-toc","default":false,},{"name":"Hide module navigation","js_name":"hide-modnav","default":false,},{"name":"Disable keyboard shortcuts","js_name":"disable-shortcuts","default":false,},{"name":"Use sans serif fonts","js_name":"sans-serif-fonts","default":false,},{"name":"Word wrap source code","js_name":"word-wrap-source-code","default":false,},];const elementKind=isSettingsPage?"section":"div";const innerHTML=`
${buildSettingsPageSections(settings)}
`;const el=document.createElement(elementKind);el.id="settings";if(!isSettingsPage){el.className="popover";}el.innerHTML=innerHTML;if(isSettingsPage){const mainElem=document.getElementById(MAIN_ID);if(mainElem!==null){mainElem.appendChild(el);}}else{el.setAttribute("tabindex","-1");const settingsBtn=getSettingsButton();if(settingsBtn!==null){settingsBtn.appendChild(el);}}return el;}const settingsMenu=buildSettingsPage();function displaySettings(){settingsMenu.style.display="";onEachLazy(settingsMenu.querySelectorAll("input[type='checkbox']"),el=>{const val=getSettingValue(el.id);const checked=val==="true";if(checked!==el.checked&&val!==null){el.checked=checked;}});}function settingsBlurHandler(event){const helpBtn=getHelpButton();const settingsBtn=getSettingsButton();const helpUnfocused=helpBtn===null||(!helpBtn.contains(document.activeElement)&&!elemContainsTarget(helpBtn,event.relatedTarget));const settingsUnfocused=settingsBtn===null||(!settingsBtn.contains(document.activeElement)&&!elemContainsTarget(settingsBtn,event.relatedTarget));if(helpUnfocused&&settingsUnfocused){window.hidePopoverMenus();}}if(!isSettingsPage){const settingsButton=nonnull(getSettingsButton());const settingsMenu=nonnull(document.getElementById("settings"));settingsButton.onclick=event=>{if(elemContainsTarget(settingsMenu,event.target)){return;}event.preventDefault();const shouldDisplaySettings=settingsMenu.style.display==="none";window.hideAllModals(false);if(shouldDisplaySettings){displaySettings();}};settingsButton.onblur=settingsBlurHandler;nonnull(settingsButton.querySelector("a")).onblur=settingsBlurHandler;onEachLazy(settingsMenu.querySelectorAll("input"),el=>{el.onblur=settingsBlurHandler;});settingsMenu.onblur=settingsBlurHandler;}setTimeout(()=>{setEvents(settingsMenu);if(!isSettingsPage){displaySettings();}removeClass(getSettingsButton(),"rotate");},0);})(); -------------------------------------------------------------------------------- /docs/api/static.files/noscript-32bb7600.css: -------------------------------------------------------------------------------- 1 | #main-content .attributes{margin-left:0 !important;}#copy-path,#sidebar-button,.sidebar-resizer{display:none !important;}nav.sub{display:none;}.src .sidebar{display:none;}.notable-traits{display:none;}:root,:root:not([data-theme]){--main-background-color:white;--main-color:black;--settings-input-color:#2196f3;--settings-input-border-color:#717171;--settings-button-color:#000;--settings-button-border-focus:#717171;--sidebar-background-color:#f5f5f5;--sidebar-background-color-hover:#e0e0e0;--sidebar-border-color:#ddd;--code-block-background-color:#f5f5f5;--scrollbar-track-background-color:#dcdcdc;--scrollbar-thumb-background-color:rgba(36,37,39,0.6);--scrollbar-color:rgba(36,37,39,0.6) #d9d9d9;--headings-border-bottom-color:#ddd;--border-color:#e0e0e0;--button-background-color:#fff;--right-side-color:grey;--code-attribute-color:#999;--toggles-color:#999;--toggle-filter:none;--mobile-sidebar-menu-filter:none;--search-input-focused-border-color:#66afe9;--copy-path-button-color:#999;--copy-path-img-filter:invert(50%);--copy-path-img-hover-filter:invert(35%);--code-example-button-color:#7f7f7f;--code-example-button-hover-color:#595959;--settings-menu-filter:invert(50%);--settings-menu-hover-filter:invert(35%);--codeblock-error-hover-color:rgb(255,0,0);--codeblock-error-color:rgba(255,0,0,.5);--codeblock-ignore-hover-color:rgb(255,142,0);--codeblock-ignore-color:rgba(255,142,0,.6);--warning-border-color:#ff8e00;--type-link-color:#ad378a;--trait-link-color:#6e4fc9;--assoc-item-link-color:#3873ad;--function-link-color:#ad7c37;--macro-link-color:#068000;--keyword-link-color:#3873ad;--mod-link-color:#3873ad;--link-color:#3873ad;--sidebar-link-color:#356da4;--sidebar-current-link-background-color:#fff;--search-result-link-focus-background-color:#ccc;--search-result-border-color:#aaa3;--search-color:#000;--search-error-code-background-color:#d0cccc;--search-results-alias-color:#000;--search-results-grey-color:#999;--search-tab-title-count-color:#888;--search-tab-button-not-selected-border-top-color:#e6e6e6;--search-tab-button-not-selected-background:#e6e6e6;--search-tab-button-selected-border-top-color:#0089ff;--search-tab-button-selected-background:#fff;--stab-background-color:#fff5d6;--stab-code-color:#000;--code-highlight-kw-color:#8959a8;--code-highlight-kw-2-color:#4271ae;--code-highlight-lifetime-color:#b76514;--code-highlight-prelude-color:#4271ae;--code-highlight-prelude-val-color:#c82829;--code-highlight-number-color:#718c00;--code-highlight-string-color:#718c00;--code-highlight-literal-color:#c82829;--code-highlight-attribute-color:#c82829;--code-highlight-self-color:#c82829;--code-highlight-macro-color:#3e999f;--code-highlight-question-mark-color:#ff9011;--code-highlight-comment-color:#8e908c;--code-highlight-doc-comment-color:#4d4d4c;--src-line-numbers-span-color:#c67e2d;--src-line-number-highlighted-background-color:#fdffd3;--target-background-color:#fdffd3;--target-border-color:#ad7c37;--kbd-color:#000;--kbd-background:#fafbfc;--kbd-box-shadow-color:#c6cbd1;--rust-logo-filter:initial;--crate-search-div-filter:invert(100%) sepia(0%) saturate(4223%) hue-rotate(289deg) brightness(114%) contrast(76%);--crate-search-div-hover-filter:invert(44%) sepia(18%) saturate(23%) hue-rotate(317deg) brightness(96%) contrast(93%);--crate-search-hover-border:#717171;--src-sidebar-background-selected:#fff;--src-sidebar-background-hover:#e0e0e0;--table-alt-row-background-color:#f5f5f5;--codeblock-link-background:#eee;--scrape-example-toggle-line-background:#ccc;--scrape-example-toggle-line-hover-background:#999;--scrape-example-code-line-highlight:#fcffd6;--scrape-example-code-line-highlight-focus:#f6fdb0;--scrape-example-help-border-color:#555;--scrape-example-help-color:#333;--scrape-example-help-hover-border-color:#000;--scrape-example-help-hover-color:#000;--scrape-example-code-wrapper-background-start:rgba(255,255,255,1);--scrape-example-code-wrapper-background-end:rgba(255,255,255,0);--sidebar-resizer-hover:hsl(207,90%,66%);--sidebar-resizer-active:hsl(207,90%,54%);}@media (prefers-color-scheme:dark){:root,:root:not([data-theme]){--main-background-color:#353535;--main-color:#ddd;--settings-input-color:#2196f3;--settings-input-border-color:#999;--settings-button-color:#000;--settings-button-border-focus:#ffb900;--sidebar-background-color:#505050;--sidebar-background-color-hover:#676767;--sidebar-border-color:#2A2A2A;--code-block-background-color:#2A2A2A;--scrollbar-track-background-color:#717171;--scrollbar-thumb-background-color:rgba(32,34,37,.6);--scrollbar-color:rgba(32,34,37,.6) #5a5a5a;--headings-border-bottom-color:#d2d2d2;--border-color:#e0e0e0;--button-background-color:#f0f0f0;--right-side-color:grey;--code-attribute-color:#999;--toggles-color:#999;--toggle-filter:invert(100%);--mobile-sidebar-menu-filter:invert(100%);--search-input-focused-border-color:#008dfd;--copy-path-button-color:#999;--copy-path-img-filter:invert(50%);--copy-path-img-hover-filter:invert(65%);--code-example-button-color:#7f7f7f;--code-example-button-hover-color:#a5a5a5;--codeblock-error-hover-color:rgb(255,0,0);--codeblock-error-color:rgba(255,0,0,.5);--codeblock-ignore-hover-color:rgb(255,142,0);--codeblock-ignore-color:rgba(255,142,0,.6);--warning-border-color:#ff8e00;--type-link-color:#2dbfb8;--trait-link-color:#b78cf2;--assoc-item-link-color:#d2991d;--function-link-color:#2bab63;--macro-link-color:#09bd00;--keyword-link-color:#d2991d;--mod-link-color:#d2991d;--link-color:#d2991d;--sidebar-link-color:#fdbf35;--sidebar-current-link-background-color:#444;--search-result-link-focus-background-color:#616161;--search-result-border-color:#aaa3;--search-color:#111;--search-error-code-background-color:#484848;--search-results-alias-color:#fff;--search-results-grey-color:#ccc;--search-tab-title-count-color:#888;--search-tab-button-not-selected-border-top-color:#252525;--search-tab-button-not-selected-background:#252525;--search-tab-button-selected-border-top-color:#0089ff;--search-tab-button-selected-background:#353535;--settings-menu-filter:invert(50%);--settings-menu-hover-filter:invert(65%);--stab-background-color:#314559;--stab-code-color:#e6e1cf;--code-highlight-kw-color:#ab8ac1;--code-highlight-kw-2-color:#769acb;--code-highlight-lifetime-color:#d97f26;--code-highlight-prelude-color:#769acb;--code-highlight-prelude-val-color:#ee6868;--code-highlight-number-color:#83a300;--code-highlight-string-color:#83a300;--code-highlight-literal-color:#ee6868;--code-highlight-attribute-color:#ee6868;--code-highlight-self-color:#ee6868;--code-highlight-macro-color:#3e999f;--code-highlight-question-mark-color:#ff9011;--code-highlight-comment-color:#8d8d8b;--code-highlight-doc-comment-color:#8ca375;--src-line-numbers-span-color:#3b91e2;--src-line-number-highlighted-background-color:#0a042f;--target-background-color:#494a3d;--target-border-color:#bb7410;--kbd-color:#000;--kbd-background:#fafbfc;--kbd-box-shadow-color:#c6cbd1;--rust-logo-filter:drop-shadow(1px 0 0px #fff) drop-shadow(0 1px 0 #fff) drop-shadow(-1px 0 0 #fff) drop-shadow(0 -1px 0 #fff);--crate-search-div-filter:invert(94%) sepia(0%) saturate(721%) hue-rotate(255deg) brightness(90%) contrast(90%);--crate-search-div-hover-filter:invert(69%) sepia(60%) saturate(6613%) hue-rotate(184deg) brightness(100%) contrast(91%);--crate-search-hover-border:#2196f3;--src-sidebar-background-selected:#333;--src-sidebar-background-hover:#444;--table-alt-row-background-color:#2a2a2a;--codeblock-link-background:#333;--scrape-example-toggle-line-background:#999;--scrape-example-toggle-line-hover-background:#c5c5c5;--scrape-example-code-line-highlight:#5b3b01;--scrape-example-code-line-highlight-focus:#7c4b0f;--scrape-example-help-border-color:#aaa;--scrape-example-help-color:#eee;--scrape-example-help-hover-border-color:#fff;--scrape-example-help-hover-color:#fff;--scrape-example-code-wrapper-background-start:rgba(53,53,53,1);--scrape-example-code-wrapper-background-end:rgba(53,53,53,0);--sidebar-resizer-hover:hsl(207,30%,54%);--sidebar-resizer-active:hsl(207,90%,54%);}} -------------------------------------------------------------------------------- /docs/api/type.impl/run_script/types/struct.ScriptOptions.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var type_impls = Object.fromEntries([["run_script",[["
Source§

impl Clone for ScriptOptions

Source§

fn clone(&self) -> ScriptOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
","Clone","run_script::ScriptOptions"],["
Source§

impl Debug for ScriptOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
","Debug","run_script::ScriptOptions"],["
Source§

impl PartialEq for ScriptOptions

Source§

fn eq(&self, other: &ScriptOptions) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient,\nand should not be overridden without very good reason.
","PartialEq","run_script::ScriptOptions"],["
Source§

impl ScriptOptions

Source

pub fn new() -> ScriptOptions

Returns new instance

\n
",0,"run_script::ScriptOptions"],["
Source§

impl StructuralPartialEq for ScriptOptions

","StructuralPartialEq","run_script::ScriptOptions"]]]]); 3 | if (window.register_type_impls) { 4 | window.register_type_impls(type_impls); 5 | } else { 6 | window.pending_type_impls = type_impls; 7 | } 8 | })() 9 | //{"start":55,"fragment_lengths":[7910]} -------------------------------------------------------------------------------- /docs/api/type.impl/run_script/types/enum.ScriptError.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var type_impls = Object.fromEntries([["run_script",[["
Source§

impl Debug for ScriptError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
","Debug","run_script::ScriptError"],["
Source§

impl Display for ScriptError

Source§

fn fmt(&self, format: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter.

\n
","Display","run_script::ScriptError"],["
Source§

impl Error for ScriptError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
","Error","run_script::ScriptError"]]]]); 3 | if (window.register_type_impls) { 4 | window.register_type_impls(type_impls); 5 | } else { 6 | window.pending_type_impls = type_impls; 7 | } 8 | })() 9 | //{"start":55,"fragment_lengths":[7931]} -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![deny( 2 | future_incompatible, 3 | keyword_idents, 4 | let_underscore, 5 | nonstandard_style, 6 | unused 7 | )] 8 | #![warn(unknown_lints)] 9 | 10 | //! # run_script 11 | //! 12 | //! Run shell scripts in [rust](https://www.rust-lang.org/). 13 | //! 14 | //! This library enables to invoke shell scripts based on their content.
15 | //! While std::process::Command works great to execute standalone command, you need more manual code to take a script 16 | //! text and execute it.
17 | //! For this purpose, this library was created. 18 | //! 19 | //! # Examples 20 | //! 21 | //! ## Basic Example 22 | //! 23 | //! ````use run_script; 24 | //! use run_script::ScriptOptions; 25 | //! 26 | //! fn main() { 27 | //! let options = ScriptOptions::new(); 28 | //! 29 | //! let args = vec![]; 30 | //! 31 | //! // run the script and get the script execution output 32 | //! let (code, output, error) = run_script::run( 33 | //! r#" 34 | //! echo "Directory Info:" 35 | //! dir 36 | //! "#, 37 | //! &args, 38 | //! &options, 39 | //! ) 40 | //! .unwrap(); 41 | //! 42 | //! println!("Exit Code: {}", code); 43 | //! println!("Output: {}", output); 44 | //! println!("Error: {}", error); 45 | //! 46 | //! // run the script and get a handle to the running child process 47 | //! let child = run_script::spawn( 48 | //! r#" 49 | //! echo "Directory Info:" 50 | //! dir 51 | //! "#, 52 | //! &args, 53 | //! &options, 54 | //! ) 55 | //! .unwrap(); 56 | //! 57 | //! let spawn_output = child.wait_with_output().unwrap(); 58 | //! 59 | //! println!("Success: {}", &spawn_output.status.success()); 60 | //! } 61 | //! ```` 62 | //! 63 | //! ## Macro Examples 64 | //! 65 | //! ```rust 66 | //! use run_script::ScriptOptions; 67 | //! 68 | //! fn main() { 69 | //! // simple call to run script with only the script text 70 | //! let (code, output, error) = run_script::run_script!( 71 | //! r#" 72 | //! echo "Test" 73 | //! exit 0 74 | //! "# 75 | //! ) 76 | //! .unwrap(); 77 | //! 78 | //! println!("Exit Code: {}", code); 79 | //! println!("Output: {}", output); 80 | //! println!("Error: {}", error); 81 | //! 82 | //! // run script invoked with the script text and options 83 | //! let options = ScriptOptions::new(); 84 | //! let (code, output, error) = run_script::run_script!( 85 | //! r#" 86 | //! echo "Test" 87 | //! exit 0 88 | //! "#, 89 | //! &options 90 | //! ) 91 | //! .unwrap(); 92 | //! 93 | //! println!("Exit Code: {}", code); 94 | //! println!("Output: {}", output); 95 | //! println!("Error: {}", error); 96 | //! 97 | //! // run script invoked with all arguments 98 | //! let options = ScriptOptions::new(); 99 | //! let (code, output, error) = run_script::run_script!( 100 | //! r#" 101 | //! echo "Test" 102 | //! exit 0 103 | //! "#, 104 | //! &vec!["ARG1".to_string(), "ARG2".to_string()], 105 | //! &options 106 | //! ) 107 | //! .unwrap(); 108 | //! 109 | //! println!("Exit Code: {}", code); 110 | //! println!("Output: {}", output); 111 | //! println!("Error: {}", error); 112 | //! 113 | //! // spawn_script! works the same as run_script! but returns the child process handle 114 | //! let child = run_script::spawn_script!( 115 | //! r#" 116 | //! echo "Test" 117 | //! exit 0 118 | //! "# 119 | //! ) 120 | //! .unwrap(); 121 | //! 122 | //! println!("PID: {}", child.id()); 123 | //! } 124 | //! ``` 125 | //! 126 | //! # Installation 127 | //! In order to use this library, just add it as a dependency: 128 | //! 129 | //! ```ini 130 | //! [dependencies] 131 | //! run_script = "*" 132 | //! ``` 133 | //! 134 | //! # Contributing 135 | //! See [contributing guide](https://github.com/sagiegurari/run_script/blob/master/.github/CONTRIBUTING.md) 136 | //! 137 | //! # License 138 | //! Developed by Sagie Gur-Ari and licensed under the 139 | //! [Apache 2](https://github.com/sagiegurari/run_script/blob/master/LICENSE) open source license. 140 | //! 141 | 142 | #[cfg(test)] 143 | #[path = "./lib_test.rs"] 144 | mod lib_test; 145 | 146 | #[cfg(doctest)] 147 | doc_comment::doctest!("../README.md"); 148 | 149 | #[macro_use] 150 | mod macros; 151 | mod runner; 152 | pub mod types; 153 | 154 | use crate::types::ScriptResult; 155 | use std::process::Child; 156 | 157 | /// Error struct 158 | pub type ScriptError = types::ScriptError; 159 | 160 | /// Options available for invoking the script 161 | pub type ScriptOptions = types::ScriptOptions; 162 | 163 | /// Io Options available for invoking the script 164 | pub type IoOptions = types::IoOptions; 165 | 166 | /// Invokes the provided script content and returns the invocation output. 167 | /// 168 | /// # Arguments 169 | /// 170 | /// * `script` - The script content 171 | /// * `args` - The script command line arguments 172 | /// * `options` - Options provided to the script runner 173 | /// 174 | /// # Example 175 | /// 176 | /// ```` 177 | /// use run_script::ScriptOptions; 178 | /// 179 | /// fn main() { 180 | /// let options = ScriptOptions::new(); 181 | /// 182 | /// let args = vec![]; 183 | /// 184 | /// let (code, output, error) = run_script::run( 185 | /// r#" 186 | /// echo "Directory Info:" 187 | /// dir 188 | /// "#, 189 | /// &args, 190 | /// &options 191 | /// ).unwrap(); 192 | /// 193 | /// println!("Exit Code: {}", code); 194 | /// println!("Output: {}", output); 195 | /// println!("Error: {}", error); 196 | /// } 197 | /// ```` 198 | pub fn run( 199 | script: &str, 200 | args: &Vec, 201 | options: &ScriptOptions, 202 | ) -> ScriptResult<(i32, String, String)> { 203 | runner::run(script, &args, &options) 204 | } 205 | 206 | /// Invokes the provided script content and returns a process handle. 207 | /// 208 | /// # Arguments 209 | /// 210 | /// * `script` - The script content 211 | /// * `args` - The script command line arguments 212 | /// * `options` - Options provided to the script runner 213 | /// 214 | /// # Example 215 | /// 216 | /// ```` 217 | /// use run_script::ScriptOptions; 218 | /// 219 | /// fn main() { 220 | /// let options = ScriptOptions::new(); 221 | /// 222 | /// let args = vec![]; 223 | /// 224 | /// let child = run_script::spawn( 225 | /// r#" 226 | /// echo "Directory Info:" 227 | /// dir 228 | /// "#, 229 | /// &args, 230 | /// &options 231 | /// ).unwrap(); 232 | /// } 233 | /// ```` 234 | pub fn spawn(script: &str, args: &Vec, options: &ScriptOptions) -> ScriptResult { 235 | runner::spawn(script, &args, &options) 236 | } 237 | 238 | /// Invokes the provided script content and returns the invocation output. 239 | /// In case of invocation error or error exit code, this function will exit the main process. 240 | /// 241 | /// # Arguments 242 | /// 243 | /// * `script` - The script content 244 | /// * `args` - The script command line arguments 245 | /// * `options` - Options provided to the script runner 246 | /// 247 | /// # Example 248 | /// 249 | /// ```` 250 | /// use run_script::ScriptOptions; 251 | /// 252 | /// fn main() { 253 | /// let options = ScriptOptions::new(); 254 | /// 255 | /// let args = vec![]; 256 | /// 257 | /// let (output, error) = run_script::run_or_exit( 258 | /// r#" 259 | /// echo "Hello World" 260 | /// "#, 261 | /// &args, 262 | /// &options 263 | /// ); 264 | /// 265 | /// println!("Output: {}", output); 266 | /// println!("Error: {}", error); 267 | /// } 268 | /// ```` 269 | pub fn run_or_exit(script: &str, args: &Vec, options: &ScriptOptions) -> (String, String) { 270 | runner::run_or_exit(script, &args, &options) 271 | } 272 | -------------------------------------------------------------------------------- /docs/api/run_script/type.ScriptOptions.html: -------------------------------------------------------------------------------- 1 | ScriptOptions in run_script - Rust

Type Alias ScriptOptions

Source
pub type ScriptOptions = ScriptOptions;
Expand description

Options available for invoking the script

2 |

Aliased Type§

pub struct ScriptOptions {
 3 |     pub runner: Option<String>,
 4 |     pub runner_args: Option<Vec<String>>,
 5 |     pub working_directory: Option<PathBuf>,
 6 |     pub input_redirection: IoOptions,
 7 |     pub output_redirection: IoOptions,
 8 |     pub exit_on_error: bool,
 9 |     pub print_commands: bool,
10 |     pub env_vars: Option<HashMap<String, String>>,
11 | }

Fields§

§runner: Option<String>

Defines the requested runner (defaults to cmd in windows and sh for other platforms)

12 |
§runner_args: Option<Vec<String>>

Args for the runner (for cmd, /C will automatically be added at the end)

13 |
§working_directory: Option<PathBuf>

The working directory of the invocation

14 |
§input_redirection: IoOptions

Default is IoOptions::Inherit

15 |
§output_redirection: IoOptions

Default is IoOptions::Pipe (only pipe enables to capture the output)

16 |
§exit_on_error: bool

Sets -e flag. Will exit on any error while running the script (not available for windows)

17 |
§print_commands: bool

Sets -x flag for printing each script command before invocation (not available for windows)

18 |
§env_vars: Option<HashMap<String, String>>

Environment environment variables to add before invocation

19 |
--------------------------------------------------------------------------------