From: x1 Date: 2005-12-04T08:03:19+09:00 Subject: Re: Problem with method that starts process, yields pid then yields return code I've hacked at it and managed to learn quite a few things in the process but I cant seem to assign the Exec class to a DRb server to handle requests. Ideally, the would be able to do something like: DRb.start_service sleep = DRbObject.new(nil, 'druby://server:2001').execute("ruby -e 'sleep 3 and exit 43'") p sleep.pid p sleep.wait I tried everything I could think of but the script kept breaking. Here's what I've got that DOES work: require 'drb' require 'thread' class Execute %w( cmd queue pipe pid thread exitstatus alive ).each{|a| attr_accessor a} def initialize(cmd) @cmd = cmd @queue = Queue.new @thread = Thread.new(queue) do |q| pipe = IO.popen(cmd) q.push pipe q.push pipe.pid begin loop{ stdout = pipe.gets or break } pipe.close q.push $?.exitstatus rescue => e q.push e end end @pipe = queue.pop @pid = queue.pop @exitstatus = nil end def wait @exitstatus = @queue.pop end end hostname = `hostname`.chomp port = "4501" #DRb.start_service "druby://#{hostname}:#{port}", Execute.new #DRb.thread.join job = Execute.new("cmd /c ruby -e 'sleep 3 and exit 42'") puts job.cmd puts job.pid puts job.wait If I uncomment the DRb lines, the server starts but clients throw an error :( On 12/2/05, ara.t.howard@noaa.gov wrote: > On Sat, 3 Dec 2005, x1 wrote: > > > it seems to work!! > > > > Let me spend some time trying to make sense of it... Thanks > > soooooooooooooooo much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! > > *grins* > > great. > > i learned a bit too : didn't know about pipe.pid > > cheers. > > -a > -- > =============================================================================== > | ara [dot] t [dot] howard [at] noaa [dot] gov > | all happiness comes from the desire for others to be happy. all misery > | comes from the desire for oneself to be happy. > | -- bodhicaryavatara > =============================================================================== > > >