From: Brian Candler Date: 2009-01-06T17:55:58+09:00 Subject: Re: Question about run external program in Ruby Zhao Yi wrote: > How can I get stderr in this method? You are already combining stderr with stdout (2>&1) To get them separately, see open3.rb in the standard library. # Open3 grants you access to stdin, stdout, and stderr when running another # program. Example: # # require "open3" # include Open3 # # stdin, stdout, stderr = popen3('nroff -man') # # Open3.popen3 can also take a block which will receive stdin, stdout and # stderr as parameters. This ensures stdin, stdout and stderr are closed # once the block exits. Example: # # require "open3" # # Open3.popen3('nroff -man') { |stdin, stdout, stderr| ... } However, since it forks twice, I believe you lose the exit status from the (grand)child. You also need to be careful not to block on reading from stdout when the child has written a large amount of data to stderr, or vice versa. (For example, you could use select, or you could have two separate threads reading from stdout and stderr) -- Posted via http://www.ruby-forum.com/.