[−][src]Struct rexpect::session::PtySession
Interact with a process with read/write/signals, etc.
Fields
process: PtyProcess
stream: 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:
- the yet unread output
- 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:
- the yet unread string, without the matching needle (empty in case of EOF and NBytes)
- 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.
fn deref(&self) -> &StreamSession<File>
[src]
impl DerefMut for PtySession
[src]
fn deref_mut(&mut self) -> &mut StreamSession<File>
[src]
Auto Trait Implementations
impl !RefUnwindSafe for PtySession
impl Send for PtySession
impl !Sync for PtySession
impl Unpin for PtySession
impl !UnwindSafe for PtySession
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,