From: Theodore Knab Date: 2004-02-11T14:28:12+09:00 Subject: Re: expect.rb -- self solved If there is a better module let me know. Never mind I found a working expect module which I added to '/usr/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 Additionally, this expect test worked pretty good for me: http://www.ksky.ne.jp/~sakae/d2/20518.html --- sample expect --------------------------------- require 'pty' require 'expect' x = '' PTY.spawn("telnet foo.bar.com") do # Do connect |r_f,w_f,pid| w_f.sync = true $expect_verbose = false ### if true, Can monitor session status = r_f.expect('login: ',timeout=30) ### login if status.nil? puts "No responce foo.bar.com" exit end w_f.print "hoge\n" r_f.expect('word: ') do w_f.print "hoge-password\n" end r_f.expect('foo% ') do ### DO ls w_f.print "ls -l\n" end r_f.expect('foo% ') do |output| x = output[0] end begin ### logout w_f.print "logout\n" rescue end end print "\n=====\nhost foo hoge's home-dir files are \n" print x print "\n" ------------------------------------------------------------------- -- ------------------------------------------ Ted Knab Chester, MD 21619 ------------------------------------------ 35570707f6274702478656021626f6c6964796f6e602f66602478656 02e6164796f6e60237471647560216e6460276c6f62616c60257e696 4797e2a0