#pipeline #cross-platform #async-io #run-command #process #async #command

process-lib

Cross-platform, asynchronous Rust library to run commands in pipelines

1 stable release

1.0.0 Oct 27, 2024
0.4.2 Apr 6, 2024
0.4.1 Mar 14, 2024
0.4.0 Feb 2, 2024
0.1.0 Aug 27, 2023

#328 in Asynchronous

Download history 94/week @ 2024-07-29 48/week @ 2024-08-05 61/week @ 2024-08-12 75/week @ 2024-08-19 160/week @ 2024-08-26 61/week @ 2024-09-02 43/week @ 2024-09-09 42/week @ 2024-09-16 144/week @ 2024-09-23 46/week @ 2024-09-30 49/week @ 2024-10-07 34/week @ 2024-10-14 100/week @ 2024-10-21 84/week @ 2024-10-28 15/week @ 2024-11-04 10/week @ 2024-11-11

211 downloads per month
Used in 12 crates (9 directly)

MIT license

20KB
279 lines

⚙️ process-lib

Cross-platform, asynchronous Rust library to run commands in pipelines.

Features

This library can be seen as a convenient async wrapper around std::process::Command:

  • Wraps commands by default with sh -c or cmd /C
  • Supports pipeline (previous command output sent as input for the next command)
  • Exposes convenient functions to export output (as string lossy for example)
  • Supports tokio and async-std async runtimes
  • Supports serde (de)serialization

The library comes with 3 cargo features, including 1 default one:

  • tokio: enables the tokio async runtime
  • async-std: enables the async-std async runtime
  • derive: enables serde support

Example

use process::{Command, Pipeline};

#[tokio::main]
async fn main() {
    // run a single command	
    let cmd = Command::new("echo hello, world!");
    let out = cmd.run().await.unwrap().to_string_lossy();
    assert_eq!(out, "hello, world!\n");
	
    // run a pipeline
    let cmd = Pipeline::new(["echo hello", "cat"]);
    let out = cmd.run().await.unwrap().to_string_lossy();
    assert_eq!(out, "hello\n");
}

See the full API documentation on docs.rs.

Sponsoring

nlnet

Special thanks to the NLnet foundation and the European Commission that helped the project to receive financial support from various programs:

If you appreciate the project, feel free to donate using one of the following providers:

GitHub Ko-fi Buy Me a Coffee Liberapay thanks.dev PayPal

Dependencies

~3–15MB
~191K SLoC