You just need to discard the error output by redirecting stderrto/dev/null
$str = shell_exec("command 2>/dev/null");
Exit without errors - stdout- will be saved in $str, as before.
, shell_exec @ try - catch, shell_exec ( PHP).
, , , .
some-command > /dev/null 2>&1, , ( ), , .
A : catch/discard stdout / stderr.
, , , , stdout stderr. (, stdout), .