From: jqwoods@... Date: 2008-03-15T03:44:59+09:00 Subject: Re: How to separate stdout & stderr from executed shell command On Mar 14, 11:40 am, jqwo...@gmail.com wrote: > I would like to create a method which executes a given shell command > and returns an array containing three things: 1) stdout of the command > as a string, 2) stderr of the command as a string, and 3) the exit > status. I'm having trouble figuring out how to get stdout and stderr > as separate output. > > Here's an illustration of the desired result I'm after: > > irb> my_exec_command("ls existant_file") > => ["existant_file\n", "", 0] > > irb> my_exec_command("ls NON_existant_file") > => ["", "ls: NON_existant_file: No such file or directory\n", 2] > > Any pointers on how to implement my_exec_command? PS: Unless there's a simpler way, if someone could just point me to an API that provides stdout and stderr of sub-processes as IO objects, I could probably figure it out from there. Thanks!