2017-02-04 01:49:04 -05:00
|
|
|
# frozen_string_literal: true
|
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
|
|
|
|
2017-02-04 01:49:04 -05:00
|
|
|
r_f.expect(/^Name.*: /) do
|
|
|
|
w_f.puts("ftp")
|
|
|
|
end
|
|
|
|
r_f.expect(/word:/) do
|
|
|
|
w_f.puts("#{username}@")
|
|
|
|
end
|
|
|
|
r_f.expect(/> /) do
|
|
|
|
w_f.puts("cd pub/ruby")
|
|
|
|
end
|
|
|
|
r_f.expect("> ") do
|
|
|
|
w_f.print "pass\n"
|
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"
|