Skip to content

Commit

Permalink
[Process] Fix backwards compatibility for invalid commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi authored and nicolas-grekas committed Sep 6, 2024
1 parent 7f2f542 commit 82d962e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions Tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 82d962e

Please sign in to comment.