How do I capture the prompt, which is being sent back through telnet, using the OS's telnet? This groovy one-liner doesn't capture the prompt, which is Press Return to continue:
.
I believe this is called the "line turnaround prompt" in telnet.
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.
the underlying problem is that Java uses ProcessBuilder
to launch the OS's telnet application. 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). 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