Skip to main content

PtySession

Struct PtySession 

Source
pub struct PtySession { /* private fields */ }
Expand description

A spawned PTY session with captured output.

Implementations§

Source§

impl PtySession

Source

pub fn read_output(&mut self) -> Vec<u8>

Read any available output without blocking.

Source

pub fn read_output_result(&mut self) -> Result<Vec<u8>>

Read any available output without blocking (fallible).

Source

pub fn read_until( &mut self, pattern: &[u8], timeout: Duration, ) -> Result<Vec<u8>>

Read output until a pattern is found or a timeout elapses. Uses bounded retries for transient read errors.

Source

pub fn read_until_with_options( &mut self, pattern: &[u8], options: ReadUntilOptions, ) -> Result<Vec<u8>>

Read output until a pattern is found, with configurable retry behavior.

This variant supports:

  • Bounded retries on transient errors (e.g., WouldBlock, Interrupted)
  • Minimum bytes threshold before pattern matching
  • Configurable retry delay
§Example
let options = ReadUntilOptions::with_timeout(Duration::from_secs(5))
    .retries(3)
    .retry_delay(Duration::from_millis(50))
    .min_bytes(10);
let output = session.read_until_with_options(b"ready", options)?;
Source

pub fn send_input(&mut self, bytes: &[u8]) -> Result<()>

Send input bytes to the child process.

Source

pub fn wait(&mut self) -> Result<ExitStatus>

Wait for the child to exit and return its status.

Source

pub fn output(&self) -> &[u8]

Access all captured output so far.

Source

pub fn child_pid(&self) -> Option<u32>

Child process id (if available on this platform).

Source

pub fn drain_remaining(&mut self, timeout: Duration) -> Result<usize>

Drain all remaining output until EOF or timeout.

Call this after wait() to ensure all output from the child process has been captured. This is important because output may still be in transit through the PTY after the process exits.

Returns the total number of bytes drained.

Source

pub fn wait_and_drain(&mut self, drain_timeout: Duration) -> Result<ExitStatus>

Wait for the child and drain all remaining output.

This is a convenience method that combines wait() with drain_remaining(). It ensures deterministic capture by waiting for both the child to exit AND all output to be received.

Trait Implementations§

Source§

impl Debug for PtySession

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for PtySession

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V