pub struct Simplex(_);
Expand description
An implementation of Process
that is stripped from any output
pipes.
All write operations are async.
Examples
use tokio::process::Command;
use pwner::Spawner;
let mut command = Command::new("ls");
if let Ok(child) = command.spawn_owned() {
let (input_only_process, _) = child.decompose();
} else {
println!("ls command didn't start");
}
Note: On *nix platforms, the owned process will have 2 seconds between signals, which is a blocking wait.
Implementations
sourceimpl Simplex
impl Simplex
sourcepub fn id(&self) -> Option<u32>
pub fn id(&self) -> Option<u32>
Returns the OS-assigned process identifier associated with this child.
Examples
Basic usage:
use tokio::process::Command;
use pwner::Spawner;
let mut command = Command::new("ls");
if let Ok(child) = command.spawn_owned() {
let (process, _) = child.decompose();
match process.id() {
Some(pid) => println!("Child's ID is {}", pid),
None => println!("Child has already exited"),
}
} else {
println!("ls command didn't start");
}
sourcepub async fn wait(self) -> Result<ExitStatus, Error>
pub async fn wait(self) -> Result<ExitStatus, Error>
Waits for the child to exit completely, returning the status with which it exited.
The stdin handle to the child process, if any, will be closed before waiting. This helps avoid deadlock: it ensures that the child does not block waiting for input from the parent, while the parent waits for the child to exit.
Examples
Basic usage:
use pwner::{tokio::ReadSource, Spawner};
use tokio::io::{AsyncReadExt, AsyncWriteExt, BufReader};
use tokio::process::Command;
let (mut child, mut output) = Command::new("cat").spawn_owned().unwrap().decompose();
child.write_all(b"Hello\n").await.unwrap();
let status = child.wait().await.unwrap();
let mut buffer = String::new();
if status.success() {
output.read_from(ReadSource::Stdout);
} else {
output.read_from(ReadSource::Stderr);
}
let mut reader = BufReader::new(output);
reader.read_to_string(&mut buffer).await.unwrap();
Errors
Relays the error from tokio::process::Child::wait()
sourcepub fn eject(self) -> (Child, ChildStdin)
pub fn eject(self) -> (Child, ChildStdin)
Completely releases the ownership of the child process. The raw underlying process and pipes are returned and no wrapping function is applicable any longer.
Note: By ejecting the process, graceful drop will no longer be available.
Examples
Basic usage:
use tokio::io::{ AsyncReadExt, AsyncWriteExt };
use tokio::process::Command;
use pwner::Spawner;
let (child, mut output) = Command::new("cat").spawn_owned().unwrap().decompose();
let mut buffer = [0_u8; 1024];
let (process, mut stdin) = child.eject();
stdin.write_all(b"hello\n").await.unwrap();
output.read(&mut buffer).await.unwrap();
// Graceful drop will not be executed for `child` as the ejected variable leaves scope here
sourcepub async fn shutdown(self) -> Result<ExitStatus>
pub async fn shutdown(self) -> Result<ExitStatus>
Consumes the process to allow awaiting for shutdown.
This method is essentially the same as a drop
, however it return a Future
which allows
the parent to await the shutdown.
Examples
Basic usage:
use tokio::process::Command;
use pwner::Spawner;
let (child, _) = Command::new("top").spawn_owned().unwrap().decompose();
child.shutdown().await.unwrap();
Errors
If failure when killing the process.
Trait Implementations
sourceimpl AsyncWrite for Simplex
impl AsyncWrite for Simplex
sourcefn poll_write(
self: Pin<&mut Self>,
ctx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write(
self: Pin<&mut Self>,
ctx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
buf
into the object. Read moresourcefn poll_flush(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<()>>
sourcefn poll_shutdown(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_shutdown(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<()>>
sourcefn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize, Error>>
fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize, Error>>
poll_write
, except that it writes from a slice of buffers. Read moresourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. Read more