|
20 | 20 | class ExecutableFinder
|
21 | 21 | {
|
22 | 22 | private $suffixes = ['.exe', '.bat', '.cmd', '.com'];
|
| 23 | + private const CMD_BUILTINS = [ |
| 24 | + 'assoc', 'break', 'call', 'cd', 'chdir', 'cls', 'color', 'copy', 'date', |
| 25 | + 'del', 'dir', 'echo', 'endlocal', 'erase', 'exit', 'for', 'ftype', 'goto', |
| 26 | + 'help', 'if', 'label', 'md', 'mkdir', 'mklink', 'move', 'path', 'pause', |
| 27 | + 'popd', 'prompt', 'pushd', 'rd', 'rem', 'ren', 'rename', 'rmdir', 'set', |
| 28 | + 'setlocal', 'shift', 'start', 'time', 'title', 'type', 'ver', 'vol', |
| 29 | + ]; |
23 | 30 |
|
24 | 31 | /**
|
25 | 32 | * Replaces default suffixes of executable.
|
@@ -48,6 +55,11 @@ public function addSuffix(string $suffix)
|
48 | 55 | */
|
49 | 56 | public function find(string $name, ?string $default = null, array $extraDirs = [])
|
50 | 57 | {
|
| 58 | + // windows built-in commands that are present in cmd.exe should not be resolved using PATH as they do not exist as exes |
| 59 | + if ('\\' === \DIRECTORY_SEPARATOR && \in_array(strtolower($name), self::CMD_BUILTINS, true)) { |
| 60 | + return $name; |
| 61 | + } |
| 62 | + |
51 | 63 | $dirs = array_merge(
|
52 | 64 | explode(\PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
|
53 | 65 | $extraDirs
|
|
0 commit comments