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
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
--
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.