#expect #pty #testing #terminal #automation

expectrl

A tool for automating terminal applications in Unix like Don libes expect

10 releases (5 breaking)

0.6.0 Sep 24, 2022
0.5.2 Jun 8, 2022
0.4.0 May 12, 2022
0.3.0 Mar 26, 2022
0.1.3 Jul 30, 2021

#76 in Testing

Download history 339/week @ 2022-12-02 412/week @ 2022-12-09 438/week @ 2022-12-16 348/week @ 2022-12-23 315/week @ 2022-12-30 448/week @ 2023-01-06 434/week @ 2023-01-13 450/week @ 2023-01-20 669/week @ 2023-01-27 680/week @ 2023-02-03 691/week @ 2023-02-10 787/week @ 2023-02-17 489/week @ 2023-02-24 445/week @ 2023-03-03 413/week @ 2023-03-10 318/week @ 2023-03-17

1,724 downloads per month
Used in 11 crates

MIT license

190KB
4K SLoC

Build coverage status crate docs.rs

expectrl

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:

  • Spawn process
  • Control process
  • Interact with process's IO(input/output).

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.

Usage

A general example where the program simulates a used interacting with ftp.

use expectrl::{spawn, Regex, Eof, WaitStatus, Error};

fn main() -> Result<(), Error> {
    let mut p = spawn("ftp speedtest.tele2.net")?;
    p.expect(Regex("Name \\(.*\\):"))?;
    p.send_line("anonymous")?;
    p.expect("Password")?;
    p.send_line("test")?;
    p.expect("ftp>")?;
    p.send_line("cd upload")?;
    p.expect("successfully changed.\r\nftp>")?;
    p.send_line("pwd")?;
    p.expect(Regex("[0-9]+ \"/upload\""))?;
    p.send_line("exit")?;
    p.expect(Eof)?;
    assert_eq!(p.wait()?, WaitStatus::Exited(p.pid(), 0));
}

The example inspired by the one in philippkeller/rexpect.

For more examples, check the examples directory.

Features

  • It has an async support (To enable them you must turn on an async feature).
  • It supports logging.
  • It supports interact function.
  • It works on windows.

Notes

It was originally inspired by philippkeller/rexpect and pexpect.

Licensed under MIT License

Dependencies

~0.9–32MB
~551K SLoC