[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: RExpect
From:       "James F. Hranicky" <jfh () cise ! ufl ! edu>
Date:       2005-08-19 15:51:51
Message-ID: 20050819115146.153fdfed.jfh () cise ! ufl ! edu
[Download RAW message or body]

On Fri, 19 Aug 2005 22:13:22 +0900
entropic_rune <a.griesser@gmail.com> wrote:

> Has anyone used RExpect?  Line 16 requires 'ropen3', which I have not
> been able to find.
> 
> Subsitution of  'open3'  works for all the functionality I've tested,
> although I do notice a few quirks that might be caused by this
> substitution.

I've moved to using the PTY module and the built in expect in lieu of
RExpect, as it was coring on me last time I tried it.

PTY/expect.rb seem to do a good job, and if expect is too basic you 
can roll your own. Attached is a script I used to talk to 
"apt-get upgrade" on Debian, as it's so curious. 

----------------------------------------------------------------------
| Jim Hranicky, Senior SysAdmin                   UF/CISE Department |
| E314D CSE Building                            Phone (352) 392-1499 |
| jfh@cise.ufl.edu                      http://www.cise.ufl.edu/~jfh |
----------------------------------------------------------------------

["apt-upgrade" (text/plain)]

#!/local/bin/ruby

require 'pty'
require 'timeout'

QNA = {
    /Do you want to continue\? \[Y\/n\]/                =>  'y',
    /Are you sure you want to install/			=>  'Y',
    /Should man and mandb be installed \'setuid man\'/  =>  'n',
    /Default printer resolution/                        =>  '600',
    /May I update your system\? \[Y\/n\]/               =>  'y',
    /Select the desired X server driver/                =>  'nvidia',
    /Other destinations for which mail is accepted/     =>  '',
    /Do you want system wide readable home directories/ =>  'y',
    /Which ispell dictionary should be the/		=>  '1',
    /Which wordlist should be the system/		=>  '1',
    /What would you like to do about local.conf/	=>  '2',
    /What policy do you want to apply regarding/	=>  '1',
    /What is the layout family of your keyboard/	=>  '4',
    /What is the keys layout of your keyboard/		=>  '31',
    /Which variant do you have/				=>  '2',
    /portmap \(Y\/I\/N\/O\/D\/Z\)/			=>  'n',
    /Manage CD-ROM devices and mount points with/	=>  'n',
    /Select locales to be generated/			=>  '109 110 111',
    /Which locale should be the default/		=>  '2',
    /default=N/                                         =>  ''
}

class IO
    def getline
        line = ""
        begin timeout(1) { 
            while ((char = self.getc) != "\n")
                line << char
            end
            line << char
            return line
        }
        rescue Timeout::Error
            return line
        end

    end
end

def Main

    STDIN.sync = 1
    STDOUT.sync = 1
    STDERR.sync = 1

    ENV['TERM'] = "";

    system("apt-get update")

    cmd = ARGV.shift
    cmd ||= "apt-get upgrade"

    puts " -- #{cmd} -- "
    PTY.spawn(cmd) { |r,w,cid| 
        begin
            while line = r.getline
                puts line unless line == ""
                QNA.each { |q,a|
                    if line.match(q)
                        w.puts(a)
                    end
                }
            end
        end
    }

end

Main()


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic