From: x1 Date: 2005-12-02T22:43:39+09:00 Subject: Problem with method that starts process, yields pid then yields return code I'm trying to create a method that will kick off a new process, return it's pid.. while allowing the return code to also be captured for later examination.. [on windows platform] class Exec def process_handler # if I do the following below, it will yield the # pid which is great, but because I did not # write pipe it to {}, I don't think it's possible to capture the return_level return IO.popen("ruby -e 'sleep 2' &exit 33").pid end end puts Exec.new.process_handler.to_s # => 3389 puts $? >> 8 # => gives me an error because I didnt start IO.popen with {} As a work around, I tried the following: class Exec def process_handler # if I do the following below, it will yield the # pid which is great, but because I did not # write pipe it to {}, I don't think it's possible to capture the return_level Thread.new { p = IO.popen("ruby -e 'sleep 2' &exit 33") {} $p_return_code = $? >> 8 } return p, $p_return_code end end The problem here is, p will not be defined until the process has finished writing to the pipe {}, which will prevent the return of the pid.. Any suggestions on this? I'm not able to test this code as I'm using a machine @ an internet cafe. Kind regards, Chris