Expectrl is a tool for automating terminal applications.
Expectrl is a rust module for spawning child applications and controlling them and responding to expected patterns in process's output. Expectrl works like Don Libes' Expect. Expectrl allows your script to spawn a child application and control it as if a human were typing commands.
Using the library you can:
expectrl
like original expect
may shine when you're working with interactive applications.
If your application is not interactive you may not find the library the best choise.
A general example where the program simulates a used interacting with ftp
.
```rust use expectrl::{spawn, Regex, Eof, WaitStatus, Error};
fn main() -> Result<(), Error> { let mut p = spawn("ftp speedtest.tele2.net")?; p.expect(Regex("Name \(.*\):"))?; p.sendline("anonymous")?; p.expect("Password")?; p.sendline("test")?; p.expect("ftp>")?; p.sendline("cd upload")?; p.expect("successfully changed.\r\nftp>")?; p.sendline("pwd")?; p.expect(Regex("[0-9]+ \"/upload\""))?; p.sendline("exit")?; p.expect(Eof)?; asserteq!(p.wait()?, WaitStatus::Exited(p.pid(), 0)); } ```
The example inspired by the one in [philippkeller/rexpect].
async
support (To enable them you must turn on an async
feature).It was originally inspired by [philippkeller/rexpect] and [pexpect].
Licensed under MIT License