1 stable release
1.0.0 | Oct 27, 2024 |
---|---|
0.4.2 |
|
0.4.1 |
|
0.4.0 |
|
0.1.0 |
|
#268 in Asynchronous
102 downloads per month
Used in 12 crates
(9 directly)
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
orcmd /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 runtimeasync-std
: enables the async-std async runtimederive
: 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
Special thanks to the NLnet foundation and the European Commission that helped the project to receive financial support from various programs:
- NGI Assure in 2022
- NGI Zero Entrust in 2023
- NGI Zero Core in 2024 (still ongoing)
If you appreciate the project, feel free to donate using one of the following providers:
Dependencies
~3–14MB
~189K SLoC