merged branch Seldaek/console-win-fix (PR #4100)
Commits
-------
4171305
[Console] Use proc_open instead of exec to suppress errors when run on windows and stty is not present
Discussion
----------
[Console] Use proc_open instead of exec to suppress errors.
stty is *sometimes* there on windows, but not always, so with proc_open we can quietly return null instead of outputting errors.
/cc @gnutix: that's the error you told me about this morning in https://gist.github.com/2478037
---------------------------------------------------------------------------
by maoueh at 2012-04-24T17:46:25Z
Thx, I'm getting this in my output each time an exception is thrown in CLI. Good this should fix it :)
This commit is contained in:
commit
ba080cd228
|
@ -838,7 +838,7 @@ class Application
|
|||
return preg_replace('{^(\d+)x.*$}', '$1', $ansicon);
|
||||
}
|
||||
|
||||
if (preg_match("{rows.(\d+);.columns.(\d+);}i", exec('stty -a | grep columns'), $match)) {
|
||||
if (preg_match("{rows.(\d+);.columns.(\d+);}i", $this->getSttyColumns(), $match)) {
|
||||
return $match[1];
|
||||
}
|
||||
}
|
||||
|
@ -854,7 +854,7 @@ class Application
|
|||
return preg_replace('{^\d+x\d+ \(\d+x(\d+)\)$}', '$1', trim($ansicon));
|
||||
}
|
||||
|
||||
if (preg_match("{rows.(\d+);.columns.(\d+);}i", exec('stty -a | grep columns'), $match)) {
|
||||
if (preg_match("{rows.(\d+);.columns.(\d+);}i", $this->getSttyColumns(), $match)) {
|
||||
return $match[2];
|
||||
}
|
||||
}
|
||||
|
@ -914,6 +914,25 @@ class Application
|
|||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs and parses stty -a if it's available, suppressing any error output
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getSttyColumns()
|
||||
{
|
||||
$descriptorspec = array(1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
|
||||
$process = proc_open('stty -a | grep columns', $descriptorspec, $pipes, null, null, array('suppress_errors' => true));
|
||||
if (is_resource($process)) {
|
||||
$info = stream_get_contents($pipes[1]);
|
||||
fclose($pipes[1]);
|
||||
fclose($pipes[2]);
|
||||
proc_close($process);
|
||||
|
||||
return $info;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts commands in alphabetical order.
|
||||
*
|
||||
|
|
Reference in New Issue