Net:Telnet cmd() stop performance

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?

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