Pb with pty & expect

Hi,

i have to run a Ruby script by cron.
When the script is runned in a shell, all is ok but when the script is
runned by cron i have a strange error:

/usr/lib/ruby/1.6/expect.rb:13:in select': Child_changed: 308 (RuntimeError) from /usr/lib/ruby/1.6/expect.rb:13:in expect’
from /usr/local/bin/get_all.rb:11:in scp' from /usr/local/bin/get_all.rb:9:in spawn’
from /usr/local/bin/get_all.rb:9:in `scp’
from /usr/local/bin/get_all.rb:39

I have the following code:

···

#!/usr/bin/ruby

require ‘pty’
require ‘expect’

TMP_DIR = “/cache/tmp”

def scp(host, login, passwd, file)
PTY.spawn("/usr/bin/scp #{login}@#{host}:#{file} #{TMP_DIR} 2> /cache/tmp/err

/cache/tmp/autre"){|rio, wio, pid|
wio.sync = true
rio.expect(/ password:/){
wio.print(passwd,“\n”)
}
begin
rio.gets while 1
rescue
puts “fini”
end
}
end


I’m running ruby 1.6.7
[follc@slishub /cache/tmp]$ ruby -v
ruby 1.6.7 (2002-03-19) [i386-linux]

What is the problem ? (and the solution ? ;-))

Regards

Hi!

/usr/lib/ruby/1.6/expect.rb:13:in `select’: Child_changed: 308 (RuntimeError)

[…]

I had the same problem. The solution was, to shield the call to expect and retry
once:

retried = false
begin
output = @pty_read.expect( @prompt, timeout )
rescue
if !retried
retried = true
retry
else
raise
end
end

(maybe this should be enhanced by specifying the exceptions for that
a retry should be made).

···

On Mon, Mar 24, 2003 at 08:16:53PM +0900, Cedric Foll wrote:


chris

Christian von Mueffling wrote:

Hi!

/usr/lib/ruby/1.6/expect.rb:13:in `select’: Child_changed: 308 (RuntimeError)

[…]

I had the same problem. The solution was, to shield the call to expect and retry
once:

A better solution still is to ignore the interrupting signal.
I posted an example of a rather complete Expect class two weeks ago,
that does this.
trap(‘SIGCHLD’,‘IGNORE’)
does the trick. (On Linux, don’t know a thing about Windows).

Cheers,

Han Holl

···

On Mon, Mar 24, 2003 at 08:16:53PM +0900, Cedric Foll wrote: