Skip to content

Commit

Permalink
[Console] Fix console output with closed stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzal committed Jul 22, 2015
1 parent 0da0f9e commit 534d9fc
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/Symfony/Component/Console/Output/ConsoleOutput.php
Expand Up @@ -46,12 +46,9 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
*/
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
{
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';

parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter);

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

/**
Expand Down Expand Up @@ -129,4 +126,24 @@ private function isRunningOS400()
{
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');
}
}

0 comments on commit 534d9fc

Please sign in to comment.