Crate expectrl[−][src]
Expand description
A tool for automating terminal applications on Unix and on Windows.
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.
Example
An example for interacting via ftp.
use expectrl::{spawn, Regex, Eof, WaitStatus};
let mut p = spawn("ftp speedtest.tele2.net").unwrap();
p.expect(Regex("Name \\(.*\\):")).unwrap();
p.send_line("anonymous").unwrap();
p.expect("Password").unwrap();
p.send_line("test").unwrap();
p.expect("ftp>").unwrap();
p.send_line("cd upload").unwrap();
p.expect("successfully changed.\r\nftp>").unwrap();
p.send_line("pwd").unwrap();
p.expect(Regex("[0-9]+ \"/upload\"")).unwrap();
p.send_line("exit").unwrap();
p.expect(Eof).unwrap();
assert_eq!(p.wait().unwrap(), 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
asyncsupport (To enable them you must turn on anasyncfeature). - It supports logging.
- It supports interact function.
- It has a Windows support.
Re-exports
Modules
This module contains a InteractOptions which allows a castomization of crate::Session::interact flow.
This module contains a list of special Sessions that can be spawned.
Module contains a Session structure.
Macros
Check macros provides a convient way to check if things are available in a stream of a process.
Structs
Any matches first Needle which returns a match.
Eof consider a match when it’s reached a EOF.
NBytes matches N bytes.
Regex checks a match by regex.
Enums
ControlCode represents the standard ASCII control codes wiki
Possible return values from wait() or waitpid().
Traits
Needle an interface for search of a match in a buffer.
Functions
Spawn spawnes a new session.