I'm trying to implement a solution to enter an API command and transfer it by Telnet to a hardware device and capture the response. I've tried two different Telnet implementations, one with Net/SSH and the other with the Greenletters gem and I can successfully retrieve the response in both cases but the output I get is being sent back twice.
test = Greenletters::Process.new("telnet #{@dev_one_ip} #{@port}", :timeout => 5, :transcript => $stdout)
test.start!
test << "<test cmd>\n"
test.wait_for(:output, /(response one)(response two)/)
Expected output:
<test cmd>
Trying 192.168.1.127...
Connected to 192.168.1.127.
Escape character is '^]'.
(response one)(response two)
Actual output:
<test cmd>
Trying 192.168.1.127...
Connected to 192.168.1.127.
Escape character is '^]'.
(response one)(response two)(response one)(response two)
I'm seeing this behavior in both implementations so I suspect it's an issue with the Telnet logic itself but I can't figure out what the problem is. I can log in through a separate connection and confirm the output is only being returned once, though it is being duplicated with my script.
I also noticed if I follow up this command with another one then the second command doesn't seem to execute at all, with no response in the script and it's not arriving on the device, which I can confirm through a separate connection.
Thanks, all!
I was able to find a solution, for anyone else facing this problem. I had to go back to the original Net/Telnet implementation and make use of an optional "waittime" parameter. I defined a value for it and it started capturing the entire outputs.