From: ptkwt@... (Phil Tomson) Date: 2004-09-17T08:09:48+09:00 Subject: Re: expect.rb in 1.8.2 In article <5d4c6124040916141239321053@mail.gmail.com>, Lennon Day-Reynolds wrote: >Phil, > >The 'expect.rb' library uses 'select()', which only works for sockets >on Windows, not regular file handles, IIRC. Looking at the source, >though, it seems to only work on a single file handle at a time, >anyway, so I'm not sure what it buys you something like the >uber-simple version below. > >-- 'miniexpect.rb' >require 'timeout' > >class IO > def expect(pat, wait=9999999) > result = nil > buff = '' > begin > timeout(wait) do > c = getc.chr > buff << c > > if pat.match(buff) > result = [buff, *mat.to_a[1..-1]] > end > end > rescue Timeout::Error; end > > if block_given? > yield result > else > return result > end > end >end >-- > >-- >Lennon >rcoder.net > >