[][src]Struct rexpect::session::PtySession

pub struct PtySession {
    pub process: PtyProcess,
    pub stream: StreamSession<File>,
    pub commandname: String,
}

Interact with a process with read/write/signals, etc.

Fields

process: PtyProcessstream: StreamSession<File>commandname: String

Methods from Deref<Target = StreamSession<File>>

pub fn send_line(&mut self, line: &str) -> Result<usize>[src]

sends string and a newline to process

this is guaranteed to be flushed to the process returns number of written bytes

pub fn send(&mut self, s: &str) -> Result<usize>[src]

Send string to process. As stdin of the process is most likely buffered, you'd need to call flush() after send() to make the process actually see your input.

Returns number of written bytes

pub fn send_control(&mut self, c: char) -> Result<()>[src]

Send a control code to the running process and consume resulting output line (which is empty because echo is off)

E.g. send_control('c') sends ctrl-c. Upper/smaller case does not matter.

pub fn flush(&mut self) -> Result<()>[src]

Make sure all bytes written via send() are sent to the process

pub fn read_line(&mut self) -> Result<String>[src]

Read one line (blocking!) and return line without the newline (waits until \n is in the output fetches the line and removes \r at the end if present)

pub fn try_read(&mut self) -> Option<char>[src]

Return Some(c) if a char is ready in the stdout stream of the process, return None otherwise. This is nonblocking.

pub fn exp_eof(&mut self) -> Result<String>[src]

Wait until we see EOF (i.e. child process has terminated) Return all the yet unread output

pub fn exp_regex(&mut self, regex: &str) -> Result<(String, String)>[src]

Wait until provided regex is seen on stdout of child process. Return a tuple:

  1. the yet unread output
  2. the matched regex

Note that exp_regex("^foo") matches the start of the yet consumed output. For matching the start of the line use exp_regex("\nfoo")

pub fn exp_string(&mut self, needle: &str) -> Result<String>[src]

Wait until provided string is seen on stdout of child process. Return the yet unread output (without the matched string)

pub fn exp_char(&mut self, needle: char) -> Result<String>[src]

Wait until provided char is seen on stdout of child process. Return the yet unread output (without the matched char)

pub fn exp_any(&mut self, needles: Vec<ReadUntil>) -> Result<(String, String)>[src]

Wait until any of the provided needles is found.

Return a tuple with:

  1. the yet unread string, without the matching needle (empty in case of EOF and NBytes)
  2. the matched string

Example:

use rexpect::{spawn, ReadUntil};

let mut s = spawn("cat", Some(1000))?;
s.send_line("hello, polly!")?;
s.exp_any(vec![ReadUntil::String("hello".into()),
               ReadUntil::EOF])?;

Trait Implementations

impl Deref for PtySession[src]

type Target = StreamSession<File>

The resulting type after dereferencing.

impl DerefMut for PtySession[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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