#shell #script #platform #execute #cross-platform #exec #execution

shell_exec

Cross platform library to execute shell scripts

2 unstable releases

0.2.0 Dec 24, 2024
0.1.0 Dec 24, 2024

#10 in #exec

Download history 226/week @ 2024-12-21 24/week @ 2024-12-28 10/week @ 2025-01-04

260 downloads per month

MIT license

15KB
360 lines

Shell Exec

github crates.io

Execute shell scripts asynchronously on multiple platforms. The goal of the library is to provide a simple interface to execute a user provided script on any shell. We try to avoid as much as possible writing temporary files.

use std::time::Duration;
use shell_exec::{Execution, Shell};

let execution = Execution::builder()
    .shell(Shell::Bash)
    .cmd(
        r#"
        INPUT=`cat -`;
        echo "hello $INPUT"
        "#
        .to_string(),
    )
    .timeout(Duration::from_millis(10000))
    .build();

let data = execution.execute(b"world").await.unwrap();

assert_eq!(b"hello world"[..], data);

Dependencies

~5–16MB
~208K SLoC