20 stable releases

2.3.0 Sep 14, 2024
2.2.3 Jun 1, 2024
2.2.0 Mar 30, 2024
2.0.1 Nov 24, 2023
0.1.0 May 23, 2019

#11 in Asynchronous

Download history 370672/week @ 2024-08-03 409267/week @ 2024-08-10 412917/week @ 2024-08-17 423159/week @ 2024-08-24 402410/week @ 2024-08-31 438870/week @ 2024-09-07 409637/week @ 2024-09-14 486834/week @ 2024-09-21 491410/week @ 2024-09-28 394460/week @ 2024-10-05 387996/week @ 2024-10-12 395318/week @ 2024-10-19 367173/week @ 2024-10-26 389365/week @ 2024-11-02 366818/week @ 2024-11-09 387542/week @ 2024-11-16

1,577,314 downloads per month
Used in 1,760 crates (59 directly)

Apache-2.0 OR MIT

66KB
1K SLoC

async-process

Build License Cargo Documentation

Async interface for working with processes.

This crate is an async version of std::process.

Implementation

A background thread named "async-process" is lazily created on first use, which waits for spawned child processes to exit and then calls the wait() syscall to clean up the "zombie" processes. This is unlike the process API in the standard library, where dropping a running Child leaks its resources.

This crate uses async-io for async I/O on Unix-like systems and blocking for async I/O on Windows.

Examples

Spawn a process and collect its output:

use async_process::Command;

let out = Command::new("echo").arg("hello").arg("world").output().await?;
assert_eq!(out.stdout, b"hello world\n");

Read the output line-by-line as it gets produced:

use async_process::{Command, Stdio};
use futures_lite::{io::BufReader, prelude::*};

let mut child = Command::new("find")
    .arg(".")
    .stdout(Stdio::piped())
    .spawn()?;

let mut lines = BufReader::new(child.stdout.take().unwrap()).lines();

while let Some(line) = lines.next().await {
    println!("{}", line?);
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~3–12MB
~159K SLoC