Expand description
Holds the tokio implementation of an async process.
All potentially blocking interactions are performed async, including the dropping of child processes (on *nix platforms).
Spawning an owned tokio process
use tokio::process::Command;
use pwner::Spawner;
Command::new("ls").spawn_owned().expect("ls command failed to start");
Reading from the process
use tokio::io::AsyncReadExt;
use tokio::process::Command;
use pwner::Spawner;
let mut child = Command::new("ls").spawn_owned()?;
let mut output = String::new();
child.read_to_string(&mut output).await?;
Writing to the process
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::process::Command;
use pwner::Spawner;
let mut child = Command::new("cat").spawn_owned()?;
child.write_all(b"hello\n").await?;
let mut buffer = [0_u8; 10];
child.read(&mut buffer).await?;
Graceful dropping
Note: Only available on *nix platforms.
When the owned process gets dropped, Process
will try to kill it gracefully
by sending a SIGINT
and asynchronously wait for the process to die for 2 seconds. If the
process still doesn’t die, a SIGTERM
is sent and another chance is given, until finally a
SIGKILL
is sent.
Panics
If the process is dropped without a tokio runtime, a panic will occur.
ⓘ
use tokio::process::Command;
use pwner::Spawner;
{
let child = Command::new("ls").spawn_owned().expect("ls command failed to start");
}
Make sure that a runtime is available to kill the child process
use tokio::process::Command;
use pwner::Spawner;
#[tokio::main(flavor = "current_thread")]
async fn main() {
let child = Command::new("ls").spawn_owned().expect("ls command failed to start");
}
Structs
An implementation of
Process
that uses tokio::process
as the launcher.A readable handle for both the stdout and stderr of the child process.
Enums
Possible sources to read from