expect.rb in 1.8.2

P

Phil Tomson

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
 
L

Lennon Day-Reynolds

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
 
P

Phil Tomson

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
 
P

Phil Tomson

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top