note 29508 deleted from function.system by bjori
| From: | bjori@php.net | Date: | Wed, 23 Aug 2006 07:44:23 +0000 |
| Subject: | note 29508 deleted from function.system by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-116214@lists.php.net to get a copy of this message | ||
Note Submitter: Bill at KilgallonFamily dot com
----
I am new to PHP, but an old Unix hacker (from back in the days when that meant a good thing), so
sorry if this is old news...
Anyway, I just wanted to call a shell command, and get it's numeric status. Just the way God
intended system calls to work :) If I did not care about status, I would have used the backticks
(
/usr/bin/foo).
Anyway, it does not work (php 4.2.2). I add an argument to system that is supposed to trap the
numeric return status, and it always seems to get 198 on this system with my command, regardless of
the real return value of the command.
So I used an old school Unix hacker trick, coupled with what I think is a part of PHP that does not
seem to work the way I think it ought to, and putting these together gets what I want.
Here is the code that should work:
$resultStatus = system('/bin/ls /foo', $resultStatus);
print "$resultStatus";
But I don't think it does. I don't think the $resultStatus gets the right value.
So as a workaound, use the following code:
$resultStatus = /bin/ls /foo; echo $?;
print "$resultStatus";
$resultStatus then contains the return code of the system command, and it is a little easier then
the system / exec calls, as you get a $PATH env variable and your scripts will be less dependent on
file locations on your particular system.
Bill