1

How can I get groovy, in this case groovysh, to invoke the telnet client so that replies from the server are displayed?

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()
===> java.lang.UNIXProcess@8458f04
groovy:000> 
groovy:000> exit
thufir@mordor:~$ 

I'm aware of numerous telnet libraries for Java, but in this case, want to to execute telnet as a shell command.

Thufir
  • 8,216
  • 28
  • 125
  • 273

1 Answers1

1

execute() gives you a Java Process. In your case a UNIXProcess. If telnet executes in a non-interactive fashion (ex. you can pipe it's output to a file), then you can read the Process's InputStream to get it's output:

'telnet rainmaker.wunderground.com 3000'.execute().inputStream.eachLine { line ->
    println line
}
Emmanuel Rosa
  • 9,697
  • 2
  • 14
  • 20