#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

#333 in Asynchronous

Download history 59/week @ 2024-08-02 43/week @ 2024-08-09 83/week @ 2024-08-16 94/week @ 2024-08-23 130/week @ 2024-08-30 48/week @ 2024-09-06 47/week @ 2024-09-13 105/week @ 2024-09-20 78/week @ 2024-09-27 51/week @ 2024-10-04 43/week @ 2024-10-11 18/week @ 2024-10-18 150/week @ 2024-10-25 32/week @ 2024-11-01 11/week @ 2024-11-08 11/week @ 2024-11-15

209 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
~192K SLoC