--Multipartri__19_Aug_2005_11_51_46_-0400_H9q0mSB32w5gcyy7 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 | ---------------------------------------------------------------------- --Multipartri__19_Aug_2005_11_51_46_-0400_H9q0mSB32w5gcyy7 Content-Type: text/plain; name pt-upgrade" Content-Disposition: attachment; filename pt-upgrade" Content-Transfer-Encoding: quoted-printable #!/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() --Multipartri__19_Aug_2005_11_51_46_-0400_H9q0mSB32w5gcyy7--