#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

#268 in Asynchronous

Download history 67/week @ 2024-08-18 127/week @ 2024-08-25 104/week @ 2024-09-01 45/week @ 2024-09-08 44/week @ 2024-09-15 125/week @ 2024-09-22 62/week @ 2024-09-29 49/week @ 2024-10-06 35/week @ 2024-10-13 15/week @ 2024-10-20 169/week @ 2024-10-27 16/week @ 2024-11-03 10/week @ 2024-11-10 35/week @ 2024-11-17 29/week @ 2024-11-24 28/week @ 2024-12-01

102 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–14MB
~189K SLoC