Struct pwner::tokio::Simplex

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

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

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

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

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

Attempt to write bytes from buf into the object. Read more
Attempts to flush the object, ensuring that any buffered data reach their destination. Read more
Initiates or attempts to shut down this writer, returning success when the I/O connection has completely shut down. Read more
Like poll_write, except that it writes from a slice of buffers. Read more
Determines if this writer has an efficient poll_write_vectored implementation. Read more
Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Writes a buffer into this writer, returning how many bytes were written. Read more
Like write, except that it writes from a slice of buffers. Read more
Writes a buffer into this writer, advancing the buffer’s internal cursor. Read more
Attempts to write an entire buffer into this writer. Read more
Attempts to write an entire buffer into this writer. Read more
Writes an unsigned 8-bit integer to the underlying writer. Read more
Writes an unsigned 8-bit integer to the underlying writer. Read more
Writes an unsigned 16-bit integer in big-endian order to the underlying writer. Read more
Writes a signed 16-bit integer in big-endian order to the underlying writer. Read more
Writes an unsigned 32-bit integer in big-endian order to the underlying writer. Read more
Writes a signed 32-bit integer in big-endian order to the underlying writer. Read more
Writes an unsigned 64-bit integer in big-endian order to the underlying writer. Read more
Writes an signed 64-bit integer in big-endian order to the underlying writer. Read more
Writes an unsigned 128-bit integer in big-endian order to the underlying writer. Read more
Writes an signed 128-bit integer in big-endian order to the underlying writer. Read more
Writes an 32-bit floating point type in big-endian order to the underlying writer. Read more
Writes an 64-bit floating point type in big-endian order to the underlying writer. Read more
Writes an unsigned 16-bit integer in little-endian order to the underlying writer. Read more
Writes a signed 16-bit integer in little-endian order to the underlying writer. Read more
Writes an unsigned 32-bit integer in little-endian order to the underlying writer. Read more
Writes a signed 32-bit integer in little-endian order to the underlying writer. Read more
Writes an unsigned 64-bit integer in little-endian order to the underlying writer. Read more
Writes an signed 64-bit integer in little-endian order to the underlying writer. Read more
Writes an unsigned 128-bit integer in little-endian order to the underlying writer. Read more
Writes an signed 128-bit integer in little-endian order to the underlying writer. Read more
Writes an 32-bit floating point type in little-endian order to the underlying writer. Read more
Writes an 64-bit floating point type in little-endian order to the underlying writer. Read more
Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Shuts down the output stream, ensuring that the value can be dropped cleanly. 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.