# Odd error with expect

**URL:** <https://www.ruby-forum.com/t/odd-error-with-expect/85724>\
**Category:** Ruby\
**Created:** [February 15, 2007, 8:56pm UTC](https://www.ruby-forum.com/t/odd-error-with-expect/85724 "2007-02-15T20:56:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ebca7d/32.png) [@Amos](https://www.ruby-forum.com/u/Amos)\
**Post date:** [February 15, 2007, 8:56pm UTC](https://www.ruby-forum.com/t/odd-error-with-expect/85724/1 "2007-02-15T20:56:06Z")

</div>

I’ve had a trivial expect script in use for a while now, but with  
1.8.5-p2 it no longer functions. In fact, the example expect script  
doesn’t work either. Both produce the same exception:

$ /usr/local/bin/ruby expect\_sample.rb  
/usr/local/lib/ruby/1.8/expect.rb:17:in `expect': undefined method`chr’ for nil:NilClass (NoMethodError)  
from expect\_sample.rb:18  
from expect\_sample.rb:13:in `spawn’  
from expect\_sample.rb:13

The only ‘chr’ I see is the following in expect.rb:

```
while true
  if IO.select([self],nil,nil,timeout).nil? then
    result = nil
    break
  end
  c = getc.chr
  buf << c

```

Suggestions?

---

<div class="post-metadata">

**Author:** ![Amos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ebca7d/32.png) [@Amos](https://www.ruby-forum.com/u/Amos)\
**Post date:** [February 26, 2007, 4:18pm UTC](https://www.ruby-forum.com/t/odd-error-with-expect/85724/2 "2007-02-26T16:18:35Z")

</div>

Amos wrote:

> I’ve had a trivial expect script in use for a while now, but with  
> 1.8.5-p2 it no longer functions. In fact, the example expect script  
> doesn’t work either. Both produce the same exception:
> 
> $ /usr/local/bin/ruby expect\_sample.rb  
> /usr/local/lib/ruby/1.8/expect.rb:17:in `expect': undefined method`chr’ for nil:NilClass (NoMethodError)  
> from expect\_sample.rb:18  
> from expect\_sample.rb:13:in `spawn’  
> from expect\_sample.rb:13
> 
> The only ‘chr’ I see is the following in expect.rb:
> 
> ```
> while true
> if IO.select([self],nil,nil,timeout).nil? then
> result = nil
> break
> end
> c = getc.chr
> buf << c
> 
> ```
> 
> Suggestions?

Hi,  
I came up with the same problem, except mine was running 1.8.4 on  
Solaris - but was working running on linux.

If someone has suggestions, please let us know.

---

<div class="post-metadata">

**Author:** ![Amos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ebca7d/32.png) [@Amos](https://www.ruby-forum.com/u/Amos)\
**Post date:** [February 27, 2007, 10:33am UTC](https://www.ruby-forum.com/t/odd-error-with-expect/85724/3 "2007-02-27T10:33:19Z")

</div>

On Tue, Feb 27, 2007 at 12:18:40AM +0900, John T. wrote:

> > ```
> > from expect_sample.rb:13
> > 
> > ```
> > 
> > Suggestions?
> 
> Hi,  
> I came up with the same problem, except mine was running 1.8.4 on  
> Solaris - but was working running on linux.
> 
> If someone has suggestions, please let us know.

Well, it looks like getc is returning nil. But this is despite the fact  
that  
IO.select has said that there is data available to read.

Maybe you have discovered a problem with IO.select. Can you share your  
script which demonstrates the problem? What is the “example expect  
script”  
you are referring to? I don’t see one on my system.

$ find /usr/share/doc/ruby-1.8.5/sample -type f | xargs grep expect  
$

Or maybe the behaviour of IO.select has changed in an incompatible way,  
e.g.  
on an EOF condition.

Otherwise, there might be some sort of race condition (e.g. IO.select  
says  
the descriptor is ready but by the time you read from it, the other end  
has  
closed the connection).

As a simple workaround, you could try replacing the line “c = getc.chr”  
with:

```
c = getc
if c.nil?
  result = nil
  break
end
c = c.chr

```

Regards,

Brian.
