Edit report at http://bugs.php.net/bug.php?id=52072&edit=1
ID: 52072
User updated by: php at richardneill dot org
Reported by: php at richardneill dot org
Summary: RFE: can we have `which`
Status: Wont fix
Type: Feature/Change Request
Package: Filesystem function related
Operating System: Linux
PHP Version: Irrelevant
New Comment:
Thanks for your quick reply. I agree - it's trivial to do in userspace.
The simplest way is just to
$lastline = exec ("which $ffmpeg", $output, $retval)
if (retval){
return ($lastline)
}else{
return ($false)
}
Indeed many of the PHP functions are trivial in that sense - one could
build file_get_contents() out of fopen(),file(),fclose(), or could avoid
using unlink by a call to system("rm filename").
However the attraction of PHP is that so many of the required functions
already exist and I don't have to write them. So I think that which()
would be a useful addition.
I'm particularly thinking of the cases where php-cli is an improvement
on shell-scripting.
Previous Comments:
------------------------------------------------------------------------
[2010-06-13 02:47:08] [email protected]
This seems trivial to do in userspace to me:
function which($cmd) {
$paths = explode(':',$_ENV['PATH']);
foreach($paths as $path) {
$p = $path.'/'.$cmd;
if(file_exists($p)) return $p;
}
return false;
}
------------------------------------------------------------------------
[2010-06-13 02:34:12] php at richardneill dot org
Description:
------------
It would be nice if PHP had a builtin "which" command.
For example, which("ffmpeg") would allow the user to check whether
ffmpeg
was installed, prior to calling it with exec().
Test script:
---------------
which("ffmpeg") should return eg:
/usr/bin/ffmpeg
if the command exists, and is in the £PATH for exec(), or
false
if it doesn't exist.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52072&edit=1