当前位置: 软件>java软件
Expect 工具 Expectit
本文导语: Expectit - 是纯 Java 1.6+ 实现的 Expect 工具。简单易用和可扩展,全新编写无需依赖第三方库,使用管道和非堵塞 API 基于 NIO 实现。 Maven: net.sf.expectit expectit-core 0.3.0 使用方法: // the stream from where you read yo...
Expectit - 是纯 Java 1.6+ 实现的 Expect 工具。简单易用和可扩展,全新编写无需依赖第三方库,使用管道和非堵塞 API 基于 NIO 实现。
Maven:
net.sf.expectit expectit-core 0.3.0
使用方法:
// 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);