Struct pwner::process::Simplex

source ·
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

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

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

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

Executes the destructor for this type. Read more
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Like write, except that it writes from a slice of buffers. Read more
🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
Attempts to write an entire buffer into this writer. Read more
🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.