open4status for ruby 19 Jan 2007
open4status which is an adjustment to open3.rb thats found in the standard library returns stdin, stdout, stderr and a Process::Status object of the command that ran. This way you can determine the exit status code of the command that you passed into popen4status method.

require 'open4status'

stdin,stdout,stderr,status = Open4.popen4status( "some command here" )
puts status.exitstatus

The problem this solves is that when you use Open3.popen3 or Open4.popen4, the $? value isn’t set. Since the way that $? is set can’t be done without writing a C extension or patching ruby itself this handles the problem elegantly by returning the Process::Status object.

The Code

This is being distributed as a poor man’s way of code distribution.

I am waiting to hear back from Ryan Davis on a bug/feature request to Open3 to see if this is something he wants to include in his “codeforpeople”:http://www.rubyforge.org/projects/codeforpeople project at Rubyforge.

If not I’ll release a gem. Until then here’s the file:

“http://www.continuousthinking.com/assets/2007/1/19/open4status.rb”:http://www.continuousthinking.com/assets/2007/1/19/open4status.rb


blog comments powered by Disqus