[−][src]Struct rexpect::session::PtyReplSession
A repl session: e.g. bash or the python shell: You have a prompt where a user inputs commands and the shell executes it and writes some output
Fields
prompt: String
the prompt, used for wait_for_prompt
, e.g. ">>> " for python
pty_session: PtySession
the pty_session you prepared before (initiating the shell, maybe set a custom prompt, etc.)
see spawn_bash
for an example
quit_command: Option<String>
if set, then the quit_command is called when this object is dropped you need to provide this if the shell you're testing is not killed by just sending SIGTERM
echo_on: bool
set this to true if the repl has echo on (i.e. sends user input to stdout)
although echo is set off at pty fork (see PtyProcess::new
) a few repls still
seem to be able to send output. You may need to try with true first, and if
tests fail set this to false.
Implementations
impl PtyReplSession
[src]
pub fn wait_for_prompt(&mut self) -> Result<String>
[src]
pub fn execute(&mut self, cmd: &str, ready_regex: &str) -> Result<()>
[src]
Send cmd to repl and:
- wait for the cmd to be echoed (if
echo_on == true
) - wait for the ready string being present
Q: Why can't I just do send_line
and immediately continue?
A: Executing a command in e.g. bash causes a fork. If the Unix kernel chooses the
parent process (bash) to go first and the bash process sends e.g. Ctrl-C then the
Ctrl-C goes to nirvana.
The only way to prevent this situation is to wait for a ready string being present
in the output.
Another safe way to tackle this problem is to use send_line()
and wait_for_prompt()
Example:
use rexpect::spawn_bash; let mut p = spawn_bash(Some(1000))?; p.execute("cat <(echo ready) -", "ready")?; p.send_line("hans")?; p.exp_string("hans")?;
pub fn send_line(&mut self, line: &str) -> Result<usize>
[src]
send line to repl (and flush output) and then, if echo_on=true wait for the input to appear. Return: number of bytes written
Trait Implementations
impl Deref for PtyReplSession
[src]
impl DerefMut for PtyReplSession
[src]
fn deref_mut(&mut self) -> &mut PtySession
[src]
impl Drop for PtyReplSession
[src]
Auto Trait Implementations
impl !RefUnwindSafe for PtyReplSession
impl Send for PtyReplSession
impl !Sync for PtyReplSession
impl Unpin for PtyReplSession
impl !UnwindSafe for PtyReplSession
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>,