On Oct 30, 2008, at 2:00 PM, Hugh Sasse wrote: > On Fri, 31 Oct 2008, James Gray wrote: > >> On Oct 30, 2008, at 1:10 PM, Hugh Sasse wrote: >> >>> On Fri, 31 Oct 2008, stephan.zimmer wrote: >>> >>>> I'm using Expect inside of a ruby script to control an external >>>> program. So far I have only used libexpect from a C program and >>>> would >>>> have several questions regarding the Ruby interface of Expect, >>>> maybe >>> >>> I didn't know there was one yet. >> >> expect.rb ships with Ruby. > > Correct me if I'm wrong, but that is not Don Libes' Expect > implementation > and it has to be used with PTY. So it is not libexpect. It's not libexpect. You are right. I don't know who wrote it. It's a very short just adding a single method to IO. Here's the whole thing: $expect_verbose = false class IO def expect(pat,timeout=9999999) buf = '' case pat when String e_pat = Regexp.new(Regexp.quote(pat)) when Regexp e_pat = pat end while true if !IO.select([self],nil,nil,timeout) or eof? then result = nil break end c = getc.chr buf << c if $expect_verbose STDOUT.print c STDOUT.flush end if mat=e_pat.match(buf) then result = [buf,*mat.to_a[1..-1]] break end end if block_given? then yield result else return result end nil end end I do expect that's intended to be used with pty. James Edward Gray II