Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 684f704

Browse filesBrowse files
bug #58723 [Process] Properly deal with not-found executables on Windows (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [Process] Properly deal with not-found executables on Windows | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Removing the unexpected notices that we see on appveyor: Before: ![image](https://github.com/user-attachments/assets/d9c788ad-7b29-4b0c-9170-aa08953a5ca2) After: ![image](https://github.com/user-attachments/assets/a3dc1cc7-ce4c-4fd0-b422-1a6c745bc3d9) Commits ------- 73140eb [Process] Properly deal with not-found executables on Windows
2 parents 44ce9fa + 73140eb commit 684f704
Copy full SHA for 684f704

File tree

Expand file treeCollapse file tree

2 files changed

+18
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-8
lines changed

‎src/Symfony/Component/Process/ExecutableFinder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/ExecutableFinder.php
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,14 @@ public function find(string $name, ?string $default = null, array $extraDirs = [
7373
}
7474
}
7575

76-
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v --';
77-
if (\function_exists('exec') && ($executablePath = strtok(@exec($command.' '.escapeshellarg($name)), \PHP_EOL)) && @is_executable($executablePath)) {
76+
if (!\function_exists('exec') || \strlen($name) !== strcspn($name, '/'.\DIRECTORY_SEPARATOR)) {
77+
return $default;
78+
}
79+
80+
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where %s 2> NUL' : 'command -v -- %s';
81+
$execResult = exec(\sprintf($command, escapeshellarg($name)));
82+
83+
if (($executablePath = substr($execResult, 0, strpos($execResult, \PHP_EOL) ?: null)) && @is_executable($executablePath)) {
7884
return $executablePath;
7985
}
8086

‎src/Symfony/Component/Process/PhpExecutableFinder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/PhpExecutableFinder.php
+10-6Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ public function find(bool $includeArgs = true)
3535
{
3636
if ($php = getenv('PHP_BINARY')) {
3737
if (!is_executable($php)) {
38-
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v --';
39-
if (\function_exists('exec') && $php = strtok(exec($command.' '.escapeshellarg($php)), \PHP_EOL)) {
40-
if (!is_executable($php)) {
41-
return false;
42-
}
43-
} else {
38+
if (!\function_exists('exec') || \strlen($php) !== strcspn($php, '/'.\DIRECTORY_SEPARATOR)) {
39+
return false;
40+
}
41+
42+
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where %s 2> NUL' : 'command -v -- %s';
43+
$execResult = exec(\sprintf($command, escapeshellarg($php)));
44+
if (!$php = substr($execResult, 0, strpos($execResult, \PHP_EOL) ?: null)) {
45+
return false;
46+
}
47+
if (!is_executable($php)) {
4448
return false;
4549
}
4650
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.