I've found many ways to run a command, like exec
,system
,shell_exec
, but they all seem to return the command output.
I want only the return value (integer).
How can I do that?
<?php
$retval = something("script.sh");
I've found many ways to run a command, like exec
,system
,shell_exec
, but they all seem to return the command output.
I want only the return value (integer).
How can I do that?
<?php
$retval = something("script.sh");
You can use exec()
exec("command", $output, $retval);
echo "output: $output
";
echo "return value: $retval
";
exec()
consumes $output
and $retval
by reference and their values will be set inside of exec()
. Check the manual of exec()
again.
Btw, $output
and $retval
will get implicitly initialized, they don't need to exist before the exec()
call.