# Net:Telnet cmd() stop performance

**URL:** <https://www.ruby-forum.com/t/net-telnet-cmd-stop-performance/175512>\
**Category:** Ruby\
**Created:** [September 15, 2009, 1:38am UTC](https://www.ruby-forum.com/t/net-telnet-cmd-stop-performance/175512 "2009-09-15T01:38:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![born\_in\_USSR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@born\_in\_USSR](https://www.ruby-forum.com/u/born_in_USSR)\
**Post date:** [September 15, 2009, 1:38am UTC](https://www.ruby-forum.com/t/net-telnet-cmd-stop-performance/175512/1 "2009-09-15T01:38:46Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![born\_in\_USSR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@born\_in\_USSR](https://www.ruby-forum.com/u/born_in_USSR)\
**Post date:** [September 16, 2009, 1:34am UTC](https://www.ruby-forum.com/t/net-telnet-cmd-stop-performance/175512/2 "2009-09-16T01:34:13Z")

</div>

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
