1999-08-13 01:37:52 -04:00
|
|
|
#
|
|
|
|
# sample program of expect.rb
|
|
|
|
#
|
|
|
|
# by A. Ito
|
|
|
|
#
|
2013-07-18 09:50:32 -04:00
|
|
|
# This program reports the latest version of Ruby interpreter
|
2003-11-06 02:22:39 -05:00
|
|
|
# by connecting to ftp server at ruby-lang.org.
|
1999-08-13 01:37:52 -04:00
|
|
|
#
|
|
|
|
require 'pty'
|
|
|
|
require 'expect'
|
|
|
|
|
|
|
|
fnames = []
|
2003-11-06 02:22:39 -05:00
|
|
|
PTY.spawn("ftp ftp.ruby-lang.org") do |r_f,w_f,pid|
|
1999-08-13 01:37:52 -04:00
|
|
|
w_f.sync = true
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2003-11-06 02:22:39 -05:00
|
|
|
$expect_verbose = false
|
2009-03-05 22:56:38 -05:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
if !ENV['USER'].nil?
|
|
|
|
username = ENV['USER']
|
|
|
|
elsif !ENV['LOGNAME'].nil?
|
|
|
|
username = ENV['LOGNAME']
|
|
|
|
else
|
|
|
|
username = 'guest'
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-08-07 01:56:52 -04:00
|
|
|
r_f.expect(/^(Name).*: |(word):|> /) do
|
|
|
|
w_f.puts($1 ? "ftp" : $2 ? "#{username}@" : "cd pub/ruby")
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-11-06 02:22:39 -05:00
|
|
|
r_f.expect("> ") do
|
1999-08-13 01:37:52 -04:00
|
|
|
w_f.print "dir\n"
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-04-16 09:56:19 -04:00
|
|
|
r_f.expect(/[^\-]> /) do |output|
|
1999-08-13 01:37:52 -04:00
|
|
|
for x in output[0].split("\n")
|
2007-04-16 09:56:19 -04:00
|
|
|
if x =~ /(ruby.*?\.tar\.gz)/ then
|
1999-08-13 01:37:52 -04:00
|
|
|
fnames.push $1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
begin
|
|
|
|
w_f.print "quit\n"
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
print "The latest ruby interpreter is "
|
|
|
|
print fnames.sort.pop
|
|
|
|
print "\n"
|