简体   繁体   中英

getting linux command exit code when executed via exec/system in php

my terminology 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; ?> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM