Help: expect.rb

S

stevarino

Ruby newbie, need help with expect.rb.

I am running:
ruby 1.8.4 (2005-12-24) [sparc-solaris2.7]
(downloaded from SunFreeware.com).

When I run:

ruby expect_sample.rb

it aborts with the following error message:

/usr/local/lib/ruby/1.8/expect.rb:17: `undefined method `chr' for
nil:NilClass' (NoMethodError)

Looking at expect.rb, the relevant code is:

while true
if IO.select([self],nil,nil,timeout).nil? then
result = nil
break
end
c = getc.chr # line 17
...
end

Questions:

- It appears to me that getc is returning 'nil', which doesn't support
the 'chr' method.
but shouldn't the 'select().nil?' test prevent this?

- I assume expect.rb does not throw this error for everybody else --
any suggestions?

TIA,

Steve
 
D

Daniel Seix

stevarino said:
When I run:

ruby expect_sample.rb

it aborts with the following error message:

/usr/local/lib/ruby/1.8/expect.rb:17: `undefined method `chr' for
nil:NilClass' (NoMethodError)
- I assume expect.rb does not throw this error for everybody else --
any suggestions?

TIA,

Steve

So what's this expect_sample.rb?
 
D

Dumaiu

I'll be! You may have discovered a bug. The error you reported
appears when you call expect() on a File and the stream is exhausted
without a match. IO::select() (which I had never seen before) doesn't
check for an EOF char, so you need something like

if IO.select( [self], nil, nil, timeout ).nil? or eof?

But expect.rb probably isn't the best thing to use for a project of
any significant complexity. There's a thread somewhere on c.l.r. where
Matz posted his "real" version of expect()--you might look for
that--and there's a project on RubyForge called 'RExpect' which also
functions in a more advanced capacity.

Welcome to the newsgroup, by the way.
 
S

stevarino

expect_sample.rb is a program that uses the expect.rb library.

It's in the 1.8.4 distribution: ./ext/pty/expect_sample.rb
 
S

stevarino

Thanks for the encouragement. I'm really enjoying Ruby!

Actually, all I need to do is to ftp a file; I've since found the much
easier approach
using NET::Ftp.

But there are occasions when an expect capability is indespensible.
I'll look into RExpect.

Thanks again.

Steve
 

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,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top