expect.rb in 1.8.2

Discussion in 'Ruby' started by Phil Tomson, Sep 16, 2004.

  1. Phil Tomson

    Phil Tomson Guest

    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 Tomson, Sep 16, 2004
    #1
    1. Advertising

  2. 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
     
    Lennon Day-Reynolds, Sep 16, 2004
    #2
    1. Advertising

  3. Phil Tomson

    Phil Tomson Guest

    In article <>,
    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
    >
    >
     
    Phil Tomson, Sep 16, 2004
    #3
  4. Phil Tomson

    Phil Tomson Guest

    In article <>,
    Phil Tomson <> wrote:
    >In article <>,
    >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
    >>
    >>

    >
    >


    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
     
    Phil Tomson, Sep 17, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. niz
    Replies:
    2
    Views:
    1,926
    Simon Andrews
    Jul 23, 2003
  2. z0mb1e_fr
    Replies:
    2
    Views:
    741
    z0mb1e_fr
    Dec 3, 2003
  3. MarkD
    Replies:
    0
    Views:
    745
    MarkD
    Dec 4, 2003
  4. Simon Strandgaard

    how to expect eof with expect+pty

    Simon Strandgaard, Dec 20, 2006, in forum: Ruby
    Replies:
    4
    Views:
    358
    Simon Strandgaard
    Dec 20, 2006
  5. Phil
    Replies:
    0
    Views:
    168
Loading...

Share This Page