From: Mark Wilson Date: 2003-02-10T12:22:33+09:00 Subject: Re: Executing interactive system commands On Sunday, February 9, 2003, at 09:15 PM, Vitaly Semkin wrote: > Vitaly Semkin wrote: >> Hello. >> I need to execute SCP (secure copy) command from Ruby script on >> Windows. >> The problem is that this command needs a password to be typed and >> supports no switch or option to provide the password. >> Is there any way to catch the command's output and give it the >> passwod? > [snip] Expect is made to do what you want. There is a Windows version, although I've never used it. See the following website: http://expect.nist.gov/ There is something similar built into Ruby, expect.rb, which is in the standard library for 1.6.8. I have not used it, but it may do what you want. It is also short enough to reproduce here: $expect_verbose = false class IO def expect(pat,timeout=9999999) buf = '' case pat when String e_pat = Regexp.new(Regexp.quote(pat)) when Regexp e_pat = pat end while true if IO.select([self],nil,nil,timeout).nil? then result = nil break end c = getc.chr buf << c if $expect_verbose STDOUT.print c STDOUT.flush end if mat=e_pat.match(buf) then result = [buf,*mat.to_a[1..-1]] break end end if iterator? then yield result else return result end nil end end