#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

#354 in Asynchronous

Download history 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 36/week @ 2024-12-01 456/week @ 2024-12-08 133/week @ 2024-12-15 74/week @ 2024-12-22 36/week @ 2024-12-29 99/week @ 2025-01-05 127/week @ 2025-01-12 67/week @ 2025-01-19 91/week @ 2025-01-26 92/week @ 2025-02-02

432 downloads per month
Used in 12 crates (8 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
~194K SLoC