Lets take this command for example:
$command = "echo '/just/for/the/test /heh/' | awk '//just// {print $1}'";
When directly copying it inside shell, I get the following error:
awk: cmd. line:1: //just// {print $1}
awk: cmd. line:1: ^ unterminated regexp
But, when I exec()
it, I get status code 1 with no output:
exec($command, $output, $status);
var_dump( $command, $output, $status );
// string(69) "echo '/just/for/the/test /heh/' | awk '//just// {print $1}'"
// array(0) { }
// int(1)
How to retrieve the STDERR part of exec?
You should redirect stderr to stdout somehow like this
$stout = exec($command . " 2>&1", $output, $status);
See also here PHP StdErr after Exec()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With