Skip to content

Commit c53e469

Browse files
committed
feat(util.executable): add windows binary finder
1 parent b51feee commit c53e469

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/Util/Executable.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,30 @@ public function successful(): bool
5656
return $this->isSuccessful;
5757
}
5858

59-
protected function findBinary(string $binary)
59+
protected function findBinary(string $binary): string
6060
{
6161
if (\is_executable($binary)) {
62-
return $binary;
62+
return '"' . $binary . '"';
6363
}
6464

65-
$finder = new ExecutableFinder();
65+
$isWin = \DIRECTORY_SEPARATOR === '\\';
6666

67-
return $finder->find($binary) ?: $binary;
67+
return $isWin ? $this->findWindowsBinary($binary) : '"' . $binary . '"';
68+
}
69+
70+
protected function findWindowsBinary(string $binary): string
71+
{
72+
$paths = \explode(\PATH_SEPARATOR, \getenv('PATH') ?: \getenv('Path'));
73+
74+
foreach ($paths as $path) {
75+
foreach (['.exe', '.bat', '.cmd'] as $ext) {
76+
if (\is_file($file = $path . '\\' . $binary . $ext)) {
77+
return '"' . $file . '"';
78+
}
79+
}
80+
}
81+
82+
return '"' . $binary . '"';
6883
}
6984

7085
/**

0 commit comments

Comments
 (0)