From: James Edward Gray II Date: 2007-09-25T07:29:55+09:00 Subject: Re: communicating w/ command-line program (OR ruby expect) On Sep 24, 2007, at 5:18 PM, Cameron Matheson wrote: > Hi, > > On 9/24/07, yermej@gmail.com wrote: >> If you need to interact with something (a la irb, ftp, telnet, etc.) >> you'll need to find something else, I think. > > This is what I'm looking for (something to interact w/ a program that > has an ftp-like interface). For FTP use Net::FTP, of course. Otherwise, Ruby does ship with a simple expect library: $ cat /usr/local/lib/ruby/1.8/expect.rb $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).nil? 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 __END__ Hope that helps. James Edward Gray II