#process #spawn #command #subprocess #child

async-process

Async interface for working with processes

9 releases (5 stable)

1.2.0 Aug 7, 2021
1.1.0 Apr 24, 2021
1.0.2 Feb 5, 2021
1.0.1 Oct 9, 2020
0.1.0 May 23, 2019

#433 in Asynchronous

Download history 47820/week @ 2021-07-03 48176/week @ 2021-07-10 48548/week @ 2021-07-17 57785/week @ 2021-07-24 55050/week @ 2021-07-31 57305/week @ 2021-08-07 61438/week @ 2021-08-14 90620/week @ 2021-08-21 72066/week @ 2021-08-28 67645/week @ 2021-09-04 82161/week @ 2021-09-11 73070/week @ 2021-09-18 67549/week @ 2021-09-25 94380/week @ 2021-10-02 82063/week @ 2021-10-09 92302/week @ 2021-10-16

191,332 downloads per month
Used in 650 crates (16 directly)

Apache-2.0 OR MIT

41KB
499 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

~315–550KB