Q:

exec() (or like functions) pass back error output

I can pass back output of the executed script, but I get no error output if the script errors out.
// This is a file that doesn't exists, for testing
$command = './path/to/non/existing/script.sh';

$commandOutput = exec($command, $commandOutput); // works but no error output
//passthru($command, $commandOutput); // works but error output was 127 not file not found
//$commandOutput = escapeshellcmd($command);
echo "The Output:\n|".$commandOutput."|\n";
var_dump($commandOutput);

The Output:

||

I would like the output of the error message:
The Output:

|file not found|

How or what function/parameter would do this?

A:

You can redirect stderr to stdout so exec() et al will fetch error messages by appending 2>&1 to your command.
see http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html

