Interact with unix processes/bash the same way as pexpect or Don libes expect does
Interact with unix processes/bash the same way as pexpect or Don libes expect does
Spawn, control, and respond to expected patterns of child applications and processes, enabling the automation of interactions and testing. Components include:
The goal is to offer a similar set of functionality as pexpect.
For more examples, check the examples directory.
Simple example for interacting via ftp:
use rexpect::spawn;
use rexpect::error::*;
fn do_ftp() -> Result {
let mut p = spawn("ftp speedtest.tele2.net", Some(30_000))?;
p.exp_regex("Name \\(.*\\):")?;
p.send_line("anonymous")?;
p.exp_string("Password")?;
p.send_line("test")?;
p.exp_string("ftp>")?;
p.send_line("cd upload")?;
p.exp_string("successfully changed.\r\nftp>")?;
p.send_line("pwd")?;
p.exp_regex("[0-9]+ \"/upload\"")?;
p.send_line("exit")?;
p.exp_eof()?;
Ok(())
}
fn main() {
do_ftp().unwrap_or_else(|e| panic!("ftp job failed with {}", e));
}…One frequent bitfall with sending ctrl-c and friends is that you need to somehow ensure that the program has fully loaded, otherwise the ctrl-* goes into nirvana. There are two functions to ensure that:
execute where you need to provide a match string which is present
on stdout/stderr when the program is readywait_for_prompt which waits until the prompt is shown again…Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual-licensed as above, without any additional terms or conditions.
No open issues yet, or sync has not completed.