Skip to content

Commit 534d9fc

Browse files
committed
[Console] Fix console output with closed stdout
1 parent 0da0f9e commit 534d9fc

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/Symfony/Component/Console/Output/ConsoleOutput.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,9 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
4646
*/
4747
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
4848
{
49-
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';
50-
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';
51-
52-
parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
49+
parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter);
5350

54-
$this->stderr = new StreamOutput(fopen($errorStream, 'w'), $verbosity, $decorated, $this->getFormatter());
51+
$this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter());
5552
}
5653

5754
/**
@@ -129,4 +126,24 @@ private function isRunningOS400()
129126
{
130127
return 'OS400' === php_uname('s');
131128
}
129+
130+
/**
131+
* @return resource
132+
*/
133+
private function openOutputStream()
134+
{
135+
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';
136+
137+
return @fopen($outputStream, 'w') ?: fopen('php://output', 'w');
138+
}
139+
140+
/**
141+
* @return resource
142+
*/
143+
private function openErrorStream()
144+
{
145+
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';
146+
147+
return fopen($errorStream, 'w');
148+
}
132149
}

0 commit comments

Comments
 (0)