checking for utilities/applications in the PATH
| From: | Chris Wagner | Date: | Wed, 25 Aug 2004 19:29:38 +0000 |
| Subject: | checking for utilities/applications in the PATH | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-194743@lists.php.net to get a copy of this message | ||
hi,
i am trying to do a simple check for archiving utilities (zip, unzip,
...), to make sure they exist within the PATH, and are executable by
PHP.
i could not find a better way to do this through php, so i went ahead
and did an
exec('which ' . $utility, $output, $return_value);
then, i check the $return_value for a non-zero value, which would
indicate that the utility was not found. using GNU/Linux this seems to
work fine, but i wouldn't mind keeping my work cross-platform.
so, my question is, is there a better way to do this?
and, if not, what i have done, for now is the following:
$result = exec('which ' . $utility, $output, $return_val);
return( $result && !$return_val );
from one quick test i ran, i determined that exec() simply returns NULL
or nothing if the given utility/command doesn't exist (
which, in this
case).
so, i expect the above code to simply return true, or skip the test for
my $utility rather, if the which utility is not present on the system.
will this work as expected in all cases/systems?
thanks a lot.