From: dilinger Date: 2005-01-13T05:36:16+09:00 Subject: Re: return code from Open3.popen? Yes, there are certainly plenty out there. Really, there needs to be a consistent interface for this sort of thing; there are plenty of functions out there that execute commands (IO.popen, Kernel.system, Open3.popen3, etc) that all do slightly different things wrt $?, depending upon their implementation. That should be hidden from the user; it should also be possible to define your own method to run commands in ruby, and override $? (it is currently read-only from within ruby). Personally, I'd rather see an exception thrown if the command fails, perhaps w/ an additional argument to specify that you don't care if the command fails. How that should happen within IO.popen()'s block is interesting, though. As it stands, $? is not set until the block exits. So: IO.popen('nonexistantcommand') { |f| puts $?.exitstatus } puts $?.exitstatus The first will return the last command run *before* the popen. If the command exits immediately (ie, because the command doesn't exist), should an exception be thrown as soon as it is realized that the command failed? Or, should the block be executed regardless of whether the command failed or not, and an exception thrown after the block as completed?