Re: PEAR::System::which() inquiry
| From: | Tomas V.V.Cox | Date: | Fri, 02 Jul 2004 06:56:17 +0000 |
| Subject: | Re: PEAR::System::which() inquiry | ||
| References: | 1 | Groups: | php.pear.core |
| Request: | Send a blank email to pear-core+get-413@lists.php.net to get a copy of this message | ||
Please post the patch at the bug system, I'll surely take a look at it.
Thanks,
Tomas V.V.Cox
Philippe Jausions wrote:
Hi, (I'm posting this to PEAR Core list, since it seems like System.php belongs there) I've been looking at the which() method of the PEAR core System package, and I'm pondering something. This is mostly for Windows environment since UNIX doesn't assume any extensions for executable files. The method currently works like this: 1. If a program name only is passed to which() then it's looked for in the include_path. For Windows, a list of extensions is considered (.exe, .bat and so on...) for finding a match. 2. If a path is provided, then a straight is_executable() (or if_file() for Windows) is done to see if the path to program is "valid". So I see several discrepencies in the behaviour depending on the platform: 1. If I try to locate "cmd.exe" on Windows, which() will fail because, an extension is always added to the program name. This could be a problem when there are several programs with same base name: i.e. mysoft.exe, mysoft.bat and so on... 2. If a path is provided but without the proper extension (.exe, .bat), then which() will also fail because the possible extensions are not considered. 3. If a path is provided, no is_file() is done to verified that the path is to an executable file (AFAICS it could be a directory...). However that check is fone for program names only... Now, the patch for System.php is not hard to write, but I don't really want to spend time on it if it will be rejected... What I propose is: 1. System::which('cmd.exe') will find the program (i.e. an empty extension is also considered beside .exe, .bat, .com...) 2. Use $_ENV['PATHEXT'], if available, to get the list of possible extensions, 3. System::which('C:\Program Files\MySoft\MySoft') will find C:\Program Files\MySoft\MySoft.exe. The rational behind that is to be able to use seamless port of UNIX tools to Windows environment. For instance System::which($path_to_gnu_dir . 'patch') 4. Use is_executable() for all OS under PHP5. 5. And bonus, check the safe_mode_exec_dir instead of include_path when under safe mode... Do you think these proposals would create a BC in the method, or they are touching "undocumented" behaviors??? Let me know, -Philippe