与 Unix 进程进行交互,使用方式与 pexpect 或 Don Libes expect 相同
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.
暂无开放 Issues,或尚未同步最近议题。