Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 23c42ca

Browse files
johnkaryfabpot
authored andcommitted
[Console] Fix STDERR output text on IBM iSeries OS400
1 parent 25a50f5 commit 23c42ca

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
*/
3131
class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
3232
{
33+
/**
34+
* @var StreamOutput
35+
*/
3336
private $stderr;
3437

3538
/**
@@ -43,14 +46,12 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
4346
*/
4447
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
4548
{
46-
$outputStream = 'php://stdout';
47-
if (!$this->hasStdoutSupport()) {
48-
$outputStream = 'php://output';
49-
}
49+
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';
50+
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';
5051

5152
parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
5253

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

5657
/**
@@ -100,14 +101,32 @@ public function setErrorOutput(OutputInterface $error)
100101
* Returns true if current environment supports writing console output to
101102
* STDOUT.
102103
*
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-
*
107104
* @return bool
108105
*/
109106
protected function hasStdoutSupport()
110107
{
111-
return ('OS400' != php_uname('s'));
108+
return false === $this->isRunningOS400();
109+
}
110+
111+
/**
112+
* Returns true if current environment supports writing console output to
113+
* STDERR.
114+
*
115+
* @return bool
116+
*/
117+
protected function hasStderrSupport()
118+
{
119+
return false === $this->isRunningOS400();
120+
}
121+
122+
/**
123+
* Checks if current executing environment is IBM iSeries (OS400), which
124+
* doesn't properly convert character-encodings between ASCII to EBCDIC.
125+
*
126+
* @return bool
127+
*/
128+
private function isRunningOS400()
129+
{
130+
return 'OS400' === php_uname('s');
112131
}
113132
}

0 commit comments

Comments
 (0)