Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitbb07d18

Browse files
bug#59949 [Process] Use a pipe for stderr in pty mode to avoid mixed output between stdout and stderr (joelwurtz)
This PR was merged into the 6.4 branch.Discussion----------[Process] Use a pipe for stderr in pty mode to avoid mixed output between stdout and stderr| Q | A| ------------- | ---| Branch? | 6.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Issues |Fix#59927| License | MITThis PR split the stderr in a pipe to correctly split stdout / stderr when using `->setPty`When using `pty` for pipes, PHP will only open only one pty and share the "same" fd for all pipes (it use dup but the original fd is the same)Which means there is a possibility than stdout goes to stderr (or vice versa) when using `pty` for both stdout and stderr.I did not make a test as this behavior is erratic and happens under other conditions that are hard to find (see related issue to see reproducer, we have to do some iterations before it happens)Commits-------ba755a8 fix(process): use a pipe for stderr in pty mode to avoid mixed output between stdout and stderr
2 parents1c59de1 +ba755a8 commitbb07d18

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+
publicfunctiontestStderrNotMixedWithStdout()
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
publicfunctiontestPTYCommand()
544558
{
545559
if (!Process::isPtySupported()) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp