odd error with expect

A

Amos

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

John Tajima

Amos said:
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.
 
B

Brian Candler

Amos said:
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.

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.
 

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,982
Messages
2,570,186
Members
46,743
Latest member
WoodrowMea

Latest Threads

Top