pub struct Simplex(/* private fields */);
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§
Source§impl 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§
Source§impl Write for Simplex
impl Write for Simplex
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)