Net:Telnet cmd() stop performance

B

born in USSR

code:
require "net/telnet"
require 'timeout'

...
tserv = Net::Telnet::new("Host" => $TELNET_ADDRESS,
"Timeout" => 10,
"Prompt" => /[$%#>] \z/n)

ans=tserv.login(user_login,user_paswd)

command="ping -c 4 192.168.1.2"
ans=''

err=Timeout::timeout(5) do
tserv.cmd(command){|c| ans+=c.to_s}
end
puts ans
...

if the command is "ping 192.168.1.2" application would stop.
Timeout::timeout() doesn't stop performance tserv.cmd(command) in 5
seconds. How is it possible to stop performance or receive Ñertain
quantity of bytes from telnet-server?
 
B

born in USSR

my decision. code:
ans=''
k=Time.now
tserv.cmd("String" => command, "Timeout" => 10)do|c|
ans+=c.to_s
if Time.now-k>$TIME_LIMIT_CMD
ans+='\nToo long process\n'
break
end
end
puts ans
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top