简体   繁体   English

如何使用Groovy或Java捕获telnet提示?

[英]how can I capture the telnet prompt using either Groovy or Java?

How do I capture the prompt, which is being sent back through telnet, using the OS's telnet ? 如何捕获使用操作系统的telnet通过telnet发送回的提示? This groovy one-liner doesn't capture the prompt, which is Press Return to continue: . 这个令人讨厌的单行代码无法捕获提示,而是Press Return to continue:

I believe this is called the "line turnaround prompt" in telnet. 我相信这在telnet中称为“线路周转提示”。

groovysh: groovysh:

thufir@mordor:~$ 
thufir@mordor:~$ groovysh
Groovy Shell (1.8.6, JVM: 1.8.0_72)
Type 'help' or '\h' for help.
--------------------------------------------------------------------------------------------------------------------------------------
groovy:000> 'telnet rainmaker.wunderground.com 3000'.execute().inputStream.eachLine { line -> println line }
Trying 38.102.137.140...
Connected to rainmaker.wunderground.com.
Escape character is '^]'.
------------------------------------------------------------------------------

*               Welcome to THE WEATHER UNDERGROUND telnet service!            *

------------------------------------------------------------------------------

*                                                                            *

*   National Weather Service information provided by Alden Electronics, Inc. *

*    and updated each minute as reports come in over our data feed.          *

*                                                                            *

*   **Note: If you cannot get past this opening screen, you must use a       *

*   different version of the "telnet" program--some of the ones for IBM      *

*   compatible PC's have a bug that prevents proper connection.              *

*                                                                            *

*           comments: jmasters@wunderground.com                              *

------------------------------------------------------------------------------

The prompt, Press Return to continue: , is omitted. 提示Press Return to continue: ,被省略。

the underlying problem is that Java uses ProcessBuilder to launch the OS's telnet application. 潜在的问题是Java使用ProcessBuilder启动操作系统的telnet应用程序。 However, as above, not all output is captured. 但是,如上所述,并非所有输出都被捕获。 When there's a prompt, the last line is omitted. 出现提示时,省略最后一行。

The reason I'm not using a telnet library, such as Apache telnet, is only because Apache telnet is different from the OS's telnet (go figure). 我之所以不使用telnet库(例如Apache telnet)的原因仅是因为Apache telnet与操作系统的telnet不同(参见图)。 Yes, there are libraries, but they're not exactly the same. 是的,有库,但是它们并不完全相同。

Read in each character, rather than full lines? 读每个字符,而不是整行?

see also: 也可以看看:

https://stackoverflow.com/a/36405986/262852 https://stackoverflow.com/a/36405986/262852

https://superuser.com/a/1061649/55747 https://superuser.com/a/1061649/55747

https://stackoverflow.com/a/36451474/262852 https://stackoverflow.com/a/36451474/262852

I'm guessing that the prompt is generated by telnet , not received from the server, and so it is written to stderr rather than stdout . 我猜测提示是由telnet生成的,而不是从服务器收到的,因此它被写入stderr而不是stdout

Read the process' standard error stream too, and see if this prompt is there. 还要阅读流程的标准错误流 ,并查看该提示是否存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Java捕获视频? - How can I capture video using java? 如何在不使用 Either 的情况下在 java 中执行此操作? - How can I do this in java without using Either? 如何为我的Java应用程序提供telnet接口? - How can I provide a telnet interface to my Java application? 使用Java和正则表达式,如何捕获不确定的(?)组? - Using Java and regex, how can I capture an uncertain(?) group? 如何在java中使用正则表达式捕获多线模式? - How can I capture a multiline pattern using a regular expressions in java? 什么是Java用于在控制台中输出,以及如何在ruby中捕获它? - What is Java using to output in console, and how can I capture it in ruby? 如何使用 selenium 和 java 捕获浏览器控制台日志 - How can i capture Browser console log using selenium and java 使用Groovy(或Java)如何将org.joda.time.LocalDateTime转换为java.util.date? - Using Groovy(or Java) how can I convert a org.joda.time.LocalDateTime to a java.util.date? 如何从命令提示符或Eclipse在Windows(10)上的JOMP中运行多个线程? - How can I run multiple threads in JOMP on Windows (10) from either the command prompt or in Eclipse? 如何使用 Javascript 或 Java Servlet 获取客户端信息? - How can I get client side information using either Javascript or Java Servlets?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM