8000 [Console] Fix error output on IBM iSeries OS400 · symfony/symfony@abd1742 · GitHub
[go: up one dir, main page]

Skip to content

Commit abd1742

Browse files
committed
[Console] Fix error output on IBM iSeries OS400
1 parent 25a50f5 commit abd1742

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

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

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,12 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
4343
*/
4444
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
4545
{
46-
$outputStream = 'php://stdout';
47-
if (!$this->hasStdoutSupport()) {
48-
$outputStream = 'php://output';
49-
}
46+
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';
47+
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';
5048

5149
parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
5250

53-
$this->stderr = new StreamOutput(fopen('php://stderr', 'w'), $verbosity, $decorated, $this->getFormatter());
51+
$this->stderr = new StreamOutput(fopen($errorStream, 'w'), $verbosity, $decorated, $this->getFormatter());
5452
}
5553

5654
/**
@@ -100,14 +98,32 @@ public function setErrorOutput(OutputInterface $error)
10098
* Returns true if current environment supports writing console output to
10199
* STDOUT.
102100
*
103-
* IBM iSeries (OS400) exhibits character-encoding issues when writing to
104-
* STDOUT and doesn't properly convert ASCII to EBCDIC, resulting in garbage
105-
* output.
106-
*
107101
* @return bool
108102
*/
109103
protected function hasStdoutSupport()
110104
{
111-
return ('OS400' != php_uname('s'));
105+
return false === $this->isRunningOS400();
106+
}
107+
108+
/**
109+
* Returns true if current environment supports writing console output to
110+
* STDERR.
111+
*
112+
* @return bool
113+
*/
114+
protected function hasStderrSupport()
115+
{
116+
return false === $this->isRunningOS400();
117+
}
118+
119+
/**
120+
* Checks if current executing environment is IBM iSeries (OS400), which
121+
* doesn't properly convert character-encodings between ASCII to EBCDIC.
122+
*
123+
* @return bool
124+
*/
125+
private function isRunningOS400()
126+
{
127+
return 'OS400' === php_uname('s');
112128
}
113129
}

0 commit comments

Comments
 (0)
0