如何获取Java流以使ExpectIt驱动Telnet [英] How to get the Java stream for ExpectIt to drive Telnet
问题描述
如何获取用于telnet的Java流,以便与如下,使用Linux上的实际Telnet客户端.
How do I get the Java stream for telnet to use with the ExpectIt? Instead of using a Java library, such as Apache Telnet as below, using the actual Telnet client on Linux.
这是在期望的手册页的上下文中:
This is in the context of the man page from expect:
期望是一个与其他交互式程序对话"的程序根据脚本.
Expect is a program that "talks" to other interactive programs according to a script.
跟进问题,范围更窄,是先前的,含糊的,过于广泛的问题,其中发表了以下评论:
followup question with a much more narrow scope to a previous, vague, overly broad question where the following comment was made:
该库与其他所有Java库一样,都使用标准Java流可以来自Telnet客户端,套接字连接或任何其他流源.这是一个telnet示例:github.com/Alexey1Gavrilov/ExpectIt/blob/master/expectit-core/…–阿列克谢·加夫里洛夫(Alexey Gavrilov)
The library, as all the other Java libraries, uses standard Java streams which can come from a Telnet client, a socket connection, or any other stream source. Here is a telnet example: github.com/Alexey1Gavrilov/ExpectIt/blob/master/expectit-core/… – Alexey Gavrilov
这是
另请参阅: https://stackoverflow.com/a/4532395/262852 您可以生成telnet客户端进程并连接到该进程的输入和输出流.像这样: You can spawn a telnet client process and connect to the process's input and output streams. Something like: Here is a link to the complete example. 这篇关于如何获取Java流以使ExpectIt驱动Telnet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!推荐答案
Process process = Runtime.getRuntime().exec("telnet rainmaker.wunderground.com");
StringBuilder wholeBuffer = new StringBuilder();
Expect expect = new ExpectBuilder()
.withOutput(process.getOutputStream())
.withInputs(process.getInputStream())
.withEchoOutput(wholeBuffer)
.withEchoInput(wholeBuffer)
.withExceptionOnFailure()
.build();