getting linux command exit code when executed via exec/system in php
my termin开发者_开发技巧ology my be off, but here goes:
lets assume one executes:
/bin/somecommand
using exec or system in php
the above command returns 'exit code' (this is the terminology that may be off) '1'.
is it possible to fetch this value via php?
if possible, do this without using a 'parent' bash script. we would love to be able to fetch this directly from php rather then having to run a parent bash script, and have that script echo out the exit code.
thanks!
The manual for exec() shows that you can provide an optional third argument to collect the return status (exit code). Similarly for system(), a second optional argument.
Example from that page:
<?php echo '<pre>'; // Outputs all the result of shellcommand "ls", and returns // the last output line into $last_line. Stores the return value // of the shell command in $retval. $last_line = system('ls', $retval); // Printing additional info echo ' </pre> <hr />Last line of the output: ' . $last_line . ' <hr />Return value: ' . $retval; ?>
精彩评论