# Net::Telnet

**URL:** <https://www.ruby-forum.com/t/net-telnet/107311>\
**Category:** Ruby\
**Created:** [June 20, 2007, 11:40am UTC](https://www.ruby-forum.com/t/net-telnet/107311 "2007-06-20T11:40:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sirtyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@sirtyman](https://www.ruby-forum.com/u/sirtyman)\
**Post date:** [June 20, 2007, 11:40am UTC](https://www.ruby-forum.com/t/net-telnet/107311/1 "2007-06-20T11:40:47Z")

</div>

I’ve got an issue with following code:

`
t.cmd('String' => "iptables -t mangle -L", 'Match' => /\#/, 'Timeout' =>
15 )
{ |c|
```
      print c
      sleep 1 #THIS IS AN ISSUE I CAN'T UNDERSTAND

      if c =~ patternDup #patternDup is RegExp object
           rtrnMsg = "DUPLICATED"
           iptblsLog.info(c.to_s)
      elsif c =~ patternRules #patternRules is RegExp object
           rtrnMsg = "RULES"
           iptblsLog.info(c.to_s)
      else
           rtrnMsg = "NO RULES"
           iptblsLog.info(c.to_s)
      end #if

```
}
`

Without sleep sometimes comparison c with particular RegExp doesn’t  
work. It isn’t due to that regular expression doesn’t match string  
compared with.  
After adding the sleep everything works well.

Please, help me to understand it. Why adding sleep resolved this issue.  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![sirtyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@sirtyman](https://www.ruby-forum.com/u/sirtyman)\
**Post date:** [June 20, 2007, 12:04pm UTC](https://www.ruby-forum.com/t/net-telnet/107311/2 "2007-06-20T12:04:06Z")

</div>

Marcin T. wrote:

> ```
> if c =~ patternDup #patternDup is RegExp object
> 
> ```
> 
> }
> 
> Without sleep sometimes comparison c with particular RegExp doesn’t  
> work. It isn’t due to that regular expression doesn’t match string  
> compared with.  
> After adding the sleep everything works well.  
> It sounds to me like either c or the regexp are modified by a different  
> thread, but without knowing where they come from (or, indeed, what t is  
> and what cmd is supposed to yield), it’s difficult to guess any more…

---

<div class="post-metadata">

**Author:** ![sirtyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@sirtyman](https://www.ruby-forum.com/u/sirtyman)\
**Post date:** [June 20, 2007, 1:08pm UTC](https://www.ruby-forum.com/t/net-telnet/107311/3 "2007-06-20T13:08:33Z")

</div>

Alex Y. wrote:

> Marcin T. wrote:
> 
> > ```
> > if c =~ patternDup #patternDup is RegExp object
> > 
> > ```
> > 
> > }
> > 
> > Without sleep sometimes comparison c with particular RegExp doesn’t  
> > work. It isn’t due to that regular expression doesn’t match string  
> > compared with.  
> > After adding the sleep everything works well.  
> > It sounds to me like either c or the regexp are modified by a different  
> > thread, but without knowing where they come from (or, indeed, what t is  
> > and what cmd is supposed to yield), it’s difficult to guess any more…

It’s impossible that it is due to modification of c variable in other  
thread. This is local variable. So the regexp’s.  
t is a Net::Telnet object. And I don’t know what cmd is supposed to  
yield. Need to look into telnet.rb(???)
