8000 fix(process): use a pipe for stderr in pty mode to avoid mixed output… · symfony/symfony@ba755a8 · GitHub
[go: up one dir, main page]

Skip to content

Commit ba755a8

Browse files
committed
fix(process): use a pipe for stderr in pty mode to avoid mixed output between stdout and stderr
1 parent 647dba0 commit ba755a8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Symfony/Component/Process/Pipes/UnixPipes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function getDescriptors(): array
7474
return [
7575
['pty'],
7676
['pty'],
77-
['pty'],
77+
['pipe', 'w'], // stderr needs to be in a pipe to correctly split error and output, since PHP will use the same stream for both
7878
];
7979
}
8080

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,20 @@ public function testExitCodeTextIsNullWhenExitCodeIsNull()
540540
$this->assertNull($process->getExitCodeText());
541541
}
542542

543+
public function testStderrNotMixedWithStdout()
544+
{
545+
if (!Process::isPtySupported()) {
546+
$this->markTestSkipped('PTY is not supported on this operating system.');
547+
}
548+
549+
$process = $this->getProcess('echo "foo" && echo "bar" >&2');
550+
$process->setPty(true);
551+
$process->run();
552+
553+
$this->assertSame("foo\r\n", $process->getOutput());
554+
$this->assertSame("bar\n", $process->getErrorOutput());
555+
}
556+
543557
public function testPTYCommand()
544558
{
545559
if (!Process::isPtySupported()) {

0 commit comments

Comments
 (0)
0