Search code examples
rubyshelltelnet

Telnet not valid when opening command prompt with Ruby


When I open a command prompt manually and type the following command I get a response from the server I am pinging.

telnet <server> <port>

When I open the command prompt with Ruby, using the following command, and run the same telnet command above, I get ''telnet' is not recognized as an internal or external command, operable program or batch file.'

Ruby command:

system('start cmd.exe)

It opens the prompt fine, but the command itself is not working, and I am not sure to why that is.


Solution

  • Some good next steps are:

    • Locate telnet.exe using WHERE, then invoke system with the path to telnet.exe.
    • Instead of system, I recommend using Open3.popen3() so that you can interact with the actual telnet program via STDIN, STDOUT, and STDERR.
    • Lastly, instead of any of the above options I would suggest that you use net-telnet as it exposes an easier API to use versus wrapping the Windows Telnet client.