From: "James F. Hranicky" Date: 2005-08-20T00:51:51+09:00 Subject: Re: RExpect --Multipart=_Fri__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 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 | ---------------------------------------------------------------------- --Multipart=_Fri__19_Aug_2005_11_51_46_-0400_H9q0mSB32w5gcyy7 Content-Type: text/plain; name="apt-upgrade" Content-Disposition: attachment; filename="apt-upgrade" Content-Transfer-Encoding: quoted-printable #!/local/bin/ruby require 'pty' require 'timeout' QNA =3D { /Do you want to continue\? \[Y\/n\]/ =3D> 'y', /Are you sure you want to install/ =3D> 'Y', /Should man and mandb be installed \'setuid man\'/ =3D> 'n', /Default printer resolution/ =3D> '600', /May I update your system\? \[Y\/n\]/ =3D> 'y', /Select the desired X server driver/ =3D> 'nvidia', /Other destinations for which mail is accepted/ =3D> '', /Do you want system wide readable home directories/ =3D> 'y', /Which ispell dictionary should be the/ =3D> '1', /Which wordlist should be the system/ =3D> '1', /What would you like to do about local.conf/ =3D> '2', /What policy do you want to apply regarding/ =3D> '1', /What is the layout family of your keyboard/ =3D> '4', /What is the keys layout of your keyboard/ =3D> '31', /Which variant do you have/ =3D> '2', /portmap \(Y\/I\/N\/O\/D\/Z\)/ =3D> 'n', /Manage CD-ROM devices and mount points with/ =3D> 'n', /Select locales to be generated/ =3D> '109 110 111', /Which locale should be the default/ =3D> '2', /default=3DN/ =3D> '' } class IO def getline line =3D "" begin timeout(1) {=20 while ((char =3D self.getc) !=3D "\n") line << char end line << char return line } rescue Timeout::Error return line end end end def Main STDIN.sync =3D 1 STDOUT.sync =3D 1 STDERR.sync =3D 1 ENV['TERM'] =3D ""; system("apt-get update") cmd =3D ARGV.shift cmd ||=3D "apt-get upgrade" puts " -- #{cmd} -- " PTY.spawn(cmd) { |r,w,cid|=20 begin while line =3D r.getline puts line unless line =3D=3D "" QNA.each { |q,a| if line.match(q) w.puts(a) end } end end } end Main() --Multipart=_Fri__19_Aug_2005_11_51_46_-0400_H9q0mSB32w5gcyy7--