Crate async_process[−][src]
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?); }
Re-exports
pub use std::process::ExitStatus; |
pub use std::process::Output; |
pub use std::process::Stdio; |
Modules
unix | Unix-specific extensions. |
Structs
Child | A spawned child process. |
ChildStderr | A handle to a child process’s standard error (stderr). |
ChildStdin | A handle to a child process’s standard input (stdin). |
ChildStdout | A handle to a child process’s standard output (stdout). |
Command | A builder for spawning processes. |