From 869daa4477487d4267f0a1b4aba2906e3583e5b8 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Mon, 3 Jun 2024 22:03:14 -0400 Subject: [PATCH 1/3] Temporarily revert regression in \Symfony\Component\Process\Process::start(). --- src/Symfony/Component/Process/Process.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index fd3ad87598ae3..45cd9e9bccd62 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -309,7 +309,12 @@ public function start(?callable $callback = null, array $env = []): void $env += '\\' === \DIRECTORY_SEPARATOR ? array_diff_ukey($this->getDefaultEnv(), $env, 'strcasecmp') : $this->getDefaultEnv(); if (\is_array($commandline = $this->commandline)) { - $commandline = array_values(array_map(strval(...), $commandline)); + $commandline = implode(' ', array_map($this->escapeArgument(...), $commandline)); + + if ('\\' !== \DIRECTORY_SEPARATOR) { + // exec is mandatory to deal with sending a signal to the process + $commandline = 'exec '.$commandline; + } } else { $commandline = $this->replacePlaceholders($commandline, $env); } @@ -320,11 +325,6 @@ public function start(?callable $callback = null, array $env = []): void // last exit code is output on the fourth pipe and caught to work around --enable-sigchild $descriptors[3] = ['pipe', 'w']; - if (\is_array($commandline)) { - // exec is mandatory to deal with sending a signal to the process - $commandline = 'exec '.$this->buildShellCommandline($commandline); - } - // See https://unix.stackexchange.com/questions/71205/background-process-pipe-input $commandline = '{ ('.$commandline.') <&3 3<&- 3>/dev/null & } 3<&0;'; $commandline .= 'pid=$!; echo $pid >&3; wait $pid 2>/dev/null; code=$?; echo $code >&3; exit $code'; From 08d1522a906e2246c1c628c7506f6a818d15e2fb Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Mon, 3 Jun 2024 21:48:04 -0400 Subject: [PATCH 2/3] Add regression test. --- src/Symfony/Component/Process/Tests/ProcessTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index 653fa6d84abc2..46a0e5f297856 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -422,6 +422,17 @@ public function testGetErrorOutput() $this->assertEquals(3, preg_match_all('/ERROR/', $p->getErrorOutput(), $matches)); } + public function testErrorOutputRegression() + { + $p = new Process(['invalid_command']); + + $p->run(); + + var_dump($p->getErrorOutput()); + + $this->assertMatchesRegularExpression('/^.*invalid_command.*(\r\n|\r|\n)$/', $p->getErrorOutput()); + } + public function testFlushErrorOutput() { $p = $this->getProcessForCode('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }'); From 540f1dc13aae7f2665cb34a9ec638f970671fcc8 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Tue, 4 Jun 2024 14:13:56 -0400 Subject: [PATCH 3/3] Put back regression in \Symfony\Component\Process\Process::start(). Revert "Temporarily revert regression in \Symfony\Component\Process\Process::start()." This reverts commit 869daa4477487d4267f0a1b4aba2906e3583e5b8. --- src/Symfony/Component/Process/Process.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 45cd9e9bccd62..fd3ad87598ae3 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -309,12 +309,7 @@ public function start(?callable $callback = null, array $env = []): void $env += '\\' === \DIRECTORY_SEPARATOR ? array_diff_ukey($this->getDefaultEnv(), $env, 'strcasecmp') : $this->getDefaultEnv(); if (\is_array($commandline = $this->commandline)) { - $commandline = implode(' ', array_map($this->escapeArgument(...), $commandline)); - - if ('\\' !== \DIRECTORY_SEPARATOR) { - // exec is mandatory to deal with sending a signal to the process - $commandline = 'exec '.$commandline; - } + $commandline = array_values(array_map(strval(...), $commandline)); } else { $commandline = $this->replacePlaceholders($commandline, $env); } @@ -325,6 +320,11 @@ public function start(?callable $callback = null, array $env = []): void // last exit code is output on the fourth pipe and caught to work around --enable-sigchild $descriptors[3] = ['pipe', 'w']; + if (\is_array($commandline)) { + // exec is mandatory to deal with sending a signal to the process + $commandline = 'exec '.$this->buildShellCommandline($commandline); + } + // See https://unix.stackexchange.com/questions/71205/background-process-pipe-input $commandline = '{ ('.$commandline.') <&3 3<&- 3>/dev/null & } 3<&0;'; $commandline .= 'pid=$!; echo $pid >&3; wait $pid 2>/dev/null; code=$?; echo $code >&3; exit $code';