Yet another Java implementation of the Unix expect utility.
ExpectIt - is yet another pure Java 1.6+ implementation of the Expect tool. It is designed to be simple, easy to use and extensible. Written from scratch. Here are the features:
- Fluent-style API
- No third-party dependencies
- NIO based implementation using pipes and non-blocking API
- Extensible matcher framework
- Support regular expressions and group operations
- Support multiple input streams
- Support 'interact' loop
- Extensible filter framework to modify the input, for example, to remove non-printable ANSI terminal characters
- Custom Expect Ant Task
- Apache License
Example code:
// the stream from where you read your input data
InputStream inputStream = ...;
// the stream to where you send commands
OutputStream outputStream = ...;
Expect expect = new ExpectBuilder()
.withInputs(inputStream)
.withOutput(outputStream)
.build();
expect.sendLine("command").expect(contains("string"));
Result result = expect.expect(regexp("(.*)--?--(.*)"));
// accessing the matching group
String group = result.group(2);