Expect.rb in 1.8.2

On my Linux box I've got Ruby 1.8.1 installed and it seems to have the
expect library:

irb(main):011:0> require 'expect'
=> true
irb(main):012:0> VERSION
=> "1.8.1"

However when I try to do that on my Windows box, it doesn't know anything
about expect.

Has the expect lib been removed from 1.8.2? Or, is it just not available
on Windows? ( I thought it was just a pure-Ruby, simple implementation)

Phil

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

In article <5d4c6124040916141239321053@mail.gmail.com>,

···

Lennon Day-Reynolds <rcoder@gmail.com> 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

In article <cid4d9023v@enews1.newsguy.com>,

···

Phil Tomson <ptkwt@aracnet.com> wrote:

In article <5d4c6124040916141239321053@mail.gmail.com>,
Lennon Day-Reynolds <rcoder@gmail.com> 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

I hit 'send' a bit prematurely...

There is no PTY lib on Windows either (not surprising); all of the expect
examples I've seen seem to rely on it.

Phil