Executing commands on the server - comments?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

I've been working on a program that runs various commands on the server
and does stuff based on the result.  Sometimes, the commands error, and
exec() and shell_exec() only return the regular output, not the error.
So I wrote this function that appears to work well.

Question: Have I reinvented the wheel, and is there a function that
already does this?  If not, are there any obvious issues I may have missed?

http://pastebin.com/m18a1ef23 if you want the colour-coded version or
just read the function below:

function better_exec($command) {
  // Execute $command and return the output, error text, and
  // return value.
  // Be sure to use escapeshellarg() or escapeshellcmd() on any
  // user-supplied data that you pass to this function.
  $process = proc_open($command, array(0 => array("pipe", "r"), 1 =>
array("pipe", "w"), 2 => array("pipe", "w")), $pipes);
  if (!is_resource($process)) return false;
  $output = stream_get_contents($pipes[1]);
  $error = stream_get_contents($pipes[2]);
  fclose($pipes[1]); fclose($pipes[2]);
  $return = proc_close($process);
  return array($output, $error, $return);

Site Timeline