Go to file
notgull 46ec822896 Wait test doesn't work 2022-12-31 17:25:40 -08:00
.github Replace direct dependency on libc with rustix 2022-12-30 13:43:50 +09:00
src Wait test doesn't work 2022-12-31 17:25:40 -08:00
tests Wait test doesn't work 2022-12-31 17:25:40 -08:00
.gitignore Initial commit 2020-08-18 20:19:25 +00:00
CHANGELOG.md Release 1.6.0 2022-11-27 16:39:21 +09:00
Cargo.toml feat: Add a cleanup_zombies future 2022-12-30 19:12:44 -08:00
LICENSE-APACHE Initial version 2020-08-19 13:34:03 +00:00
LICENSE-MIT Initial version 2020-08-19 13:34:03 +00:00
README.md feat: Add a cleanup_zombies future 2022-12-30 19:12:44 -08:00
build.rs Add windows::CommandExt::raw_arg on Rust 1.62+ 2022-12-30 14:31:53 +09:00

README.md

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.

However, note that you can reap zombie processes without spawning the "async-process" thread by calling the cleanup_zombies method. The "async-process" method is therefore only spawned if no other thread calls cleanup_zombies.

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.