bug #15330 [Console] Fix console output with closed stdout (jakzal)
This PR was merged into the 2.3 branch.
Discussion
----------
[Console] Fix console output with closed stdout
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #15180
| License | MIT
| Doc PR | -
Commits
-------
534d9fc
[Console] Fix console output with closed stdout
This commit is contained in:
commit
e60795691c
@ -46,12 +46,9 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
|
|||||||
*/
|
*/
|
||||||
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
|
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
|
||||||
{
|
{
|
||||||
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';
|
parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter);
|
||||||
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';
|
|
||||||
|
|
||||||
parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
|
$this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter());
|
||||||
|
|
||||||
$this->stderr = new StreamOutput(fopen($errorStream, 'w'), $verbosity, $decorated, $this->getFormatter());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,4 +126,24 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
|
|||||||
{
|
{
|
||||||
return 'OS400' === php_uname('s');
|
return 'OS400' === php_uname('s');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return resource
|
||||||
|
*/
|
||||||
|
private function openOutputStream()
|
||||||
|
{
|
||||||
|
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';
|
||||||
|
|
||||||
|
return @fopen($outputStream, 'w') ?: fopen('php://output', 'w');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return resource
|
||||||
|
*/
|
||||||
|
private function openErrorStream()
|
||||||
|
{
|
||||||
|
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';
|
||||||
|
|
||||||
|
return fopen($errorStream, 'w');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user