Skip to content

Commit

Permalink
fix: Env PATH fetch and find exec file not works in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jul 9, 2022
1 parent b347e8c commit 82be07f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Sys.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,19 @@ public static function getCpuNum(): int
*/
public static function findExecutable(string $name, array $paths = []): string
{
$isWin = self::isWindows();
$paths = $paths ?: self::getEnvPaths();

foreach ($paths as $path) {
$filename = $path . DIRECTORY_SEPARATOR . $name;
if (is_file($filename)) {
return $filename;
}

// maybe is exe file
if ($isWin && is_file($filename . '.exe')) {
return $filename . '.exe';
}
}
return "";
}
Expand Down
2 changes: 1 addition & 1 deletion src/SysEnv.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function setEnv(string $key, int|string $value): bool
*/
public static function getEnvPaths(): array
{
$pathStr = $_SERVER['PATH'] ?? '';
$pathStr = $_SERVER['PATH'] ?? ($_SERVER['Path'] ?? '');
if (!$pathStr) {
return [];
}
Expand Down

0 comments on commit 82be07f

Please sign in to comment.