Struct Simplex

Source
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

Source

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");
}
Source

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()

Source

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 Drop for Simplex

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Write for Simplex

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Writes a buffer into this writer, returning how many bytes were written. Read more
Source§

fn flush(&mut self) -> Result<()>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more
Source§

impl Process for Simplex

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.