From: "ara.t.howard" Date: 2007-11-19T02:01:28+09:00 Subject: Re: Executing another cmdl-app with ruby and typing in a password? On Nov 18, 2007, at 12:45 AM, kazaam wrote: > Thanks for pointing me in the right direction. I now wrote a little > loop to do this work: > > require 'pty' > require 'expect' > > PTY.spawn("ruby test.rb") do |read_t,write_t,pid| > write_t.sync = true > read_t.expect(/^enter passphrase.*/) {write_t.print "123456"} > end > > But I have a problem. How to find out if the spawned process > executed with or without errors? I mean in this example "ruby > test.rb". If I use system I could do: > puts "error" if not system("ruby test.rb") > > But PTY.spawn always just returns 'nil'. Is there any way I can > check for correct execution? > > > -- > kazaam cfp:~ > cat a.rb require "yaml" require "pty" module PTY def self.execute *a, &b begin spawn *a, &b 0 rescue => e e.status rescue raise end end end status = PTY.execute "ruby" do |r,w,pid| w.sync = true w.puts "42" y 'gets' => r.gets.strip.to_i end y 'status' => status cfp:~ > ruby a.rb --- gets: 42 --- status: 0 a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama