Example:
If you run a simple command like cc at the command prompt, you would get the output as following
$ cc
i686-apple-darwin10-gcc-4.2.1: no input files
$
If u run the same command using PHP exec command $cmd = "cc";
exec($cmd,$out);
print_r($out);
The output would be and empty array: Array ( )
So, In order to get the error string as well, we need to append 2>&1 $cmd = "cc 2>&1";
exec($cmd,$out);
print_r($out);
The output will print: Array ( [0] => i686-apple-darwin10-gcc-4.2.1: no input files )
Thank you very much this really helped me, but why is it not redirecting out to the $out variable by default that one needs to use that?
ReplyDeleteSouth Africa :)
Thank you for your comment Paul... One need to do it in order to redirect the error strings from stderr to stdout
ReplyDelete