pub struct Simplex(_);
Expand description
An implementation of Process
that is stripped from any output
pipes.
All write operations are sync.
Examples
use std::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) -> u32
pub fn id(&self) -> u32
Returns the OS-assigned process identifier associated with this child.
Examples
Basic usage:
use std::process::Command;
use pwner::Spawner;
let mut command = Command::new("ls");
if let Ok(child) = command.spawn_owned() {
let (process, _) = child.decompose();
println!("Child's ID is {}", process.id());
} else {
println!("ls command didn't start");
}
sourcepub fn wait(self) -> Result<ExitStatus, Error>
pub 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::{process::ReadSource, Spawner};
use std::io::{BufReader, Read, Write};
use std::process::Command;
let (mut child, mut output) = Command::new("cat").spawn_owned().unwrap().decompose();
child.write_all(b"Hello\n").unwrap();
let status = child.wait().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).unwrap();
Errors
Relays the error from std::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 std::io::{ Read, Write };
use std::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").unwrap();
output.read(&mut buffer).unwrap();
// Graceful drop will not be executed for `child` as the ejected variable leaves scope here
Trait Implementations
sourceimpl Write for Simplex
impl Write for Simplex
sourcefn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
sourcefn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · sourcefn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
sourcefn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)