#process #spawn #command #subprocess #child

async-process

Async interface for working with processes

7 releases (3 stable)

1.0.2 Feb 5, 2021
1.0.1 Oct 9, 2020
1.0.0 Sep 7, 2020
0.1.3 Aug 26, 2020
0.1.0 May 23, 2019

#253 in Asynchronous

Download history 3704/week @ 2020-11-10 3648/week @ 2020-11-17 4533/week @ 2020-11-24 3753/week @ 2020-12-01 9981/week @ 2020-12-08 17282/week @ 2020-12-15 14118/week @ 2020-12-22 15785/week @ 2020-12-29 22392/week @ 2021-01-05 23555/week @ 2021-01-12 20631/week @ 2021-01-19 22151/week @ 2021-01-26 22931/week @ 2021-02-02 25616/week @ 2021-02-09 29873/week @ 2021-02-16 25444/week @ 2021-02-23

58,946 downloads per month
Used in 391 crates (13 directly)

Apache-2.0 OR MIT

36KB
407 lines

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

~395–630KB
~11K SLoC