note 38044 rejected from function.system by didou
| From: | didou@php.net | Date: | Fri, 02 Jan 2004 22:33:31 +0000 |
| Subject: | note 38044 rejected from function.system by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-62817@lists.php.net to get a copy of this message | ||
Note Submitter: php@chaska.com
----
The documentation says the second argument, if present, returns the "return status code"
of the executed command. It also claims the PHP system() function is "just like the C
version" which might lead one to think that the "return status code" is the same
returned status code that the C system(3) command returns.
It is not.
For executed commands that exit normally (no signal was caught), the returned value in the second
argument is the 8-bit integer value passed to the exit(3) command. For programs that exit with a
signal, I don't know what PHP will return, but it's probably useless or wrong data.
The C system(3) function returns an integer status code, which contains as one of its 8-bit bytes,
the above 8-bit exit() value. (On BSD systems, it's actually the second byte, that is, is
obtained by this expression: status >> 8. See /usr/include/sys/wait.h.)
Anyone who has done compiled language programming on Unix systems (e.g. C, C++) may get bitten by
this misleading documentation.