From 82d962eed80966a41220bd28424ba6a71d3f357d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Auswo=CC=88ger?= Date: Thu, 5 Sep 2024 23:34:25 +0200 Subject: [PATCH] [Process] Fix backwards compatibility for invalid commands --- Process.php | 5 +++++ Tests/ProcessTest.php | 9 ++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Process.php b/Process.php index fd3ad875..878296b6 100644 --- a/Process.php +++ b/Process.php @@ -358,6 +358,11 @@ public function start(?callable $callback = null, array $env = []): void try { $process = @proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options); + + // Ensure array vs string commands behave the same + if (!$process && \is_array($commandline)) { + $process = @proc_open('exec '.$this->buildShellCommandline($commandline), $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options); + } } finally { if ($this->ignoredSignals && \function_exists('pcntl_sigprocmask')) { // we restore the signal mask here to avoid any side effects diff --git a/Tests/ProcessTest.php b/Tests/ProcessTest.php index 005b9175..3b0533b7 100644 --- a/Tests/ProcessTest.php +++ b/Tests/ProcessTest.php @@ -72,13 +72,8 @@ public function testInvalidCwd() */ public function testInvalidCommand(Process $process) { - try { - $this->assertSame('\\' === \DIRECTORY_SEPARATOR ? 1 : 127, $process->run()); - } catch (ProcessStartFailedException $e) { - // An invalid command might already fail during start since PHP 8.3 for platforms - // supporting posix_spawn(), see https://github.com/php/php-src/issues/12589 - $this->assertStringContainsString('No such file or directory', $e->getMessage()); - } + // An invalid command should not fail during start + $this->assertSame('\\' === \DIRECTORY_SEPARATOR ? 1 : 127, $process->run()); } public function invalidProcessProvider()