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

#6 in Asynchronous

Download history 416517/week @ 2024-08-22 392539/week @ 2024-08-29 440740/week @ 2024-09-05 428263/week @ 2024-09-12 456337/week @ 2024-09-19 486851/week @ 2024-09-26 440487/week @ 2024-10-03 380904/week @ 2024-10-10 398628/week @ 2024-10-17 378154/week @ 2024-10-24 381727/week @ 2024-10-31 360289/week @ 2024-11-07 398685/week @ 2024-11-14 360858/week @ 2024-11-21 348804/week @ 2024-11-28 332268/week @ 2024-12-05

1,503,816 downloads per month
Used in 1,778 crates (61 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
~158K SLoC