From cf1e02d9ae338c889862b160b61177f87a1d9c9c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 15 Oct 2012 17:06:38 +0200 Subject: [PATCH] [Console] Fix error when mode is not in PATH --- src/Symfony/Component/Console/Application.php | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index e9ff3125451f4..756b63e08d698 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -854,8 +854,7 @@ protected function getTerminalWidth() return preg_replace('{^(\d+)x.*$}', '$1', $ansicon); } - exec('mode CON', $execData); - if (preg_match('{columns:\s*(\d+)}i', $execData[4], $matches)) { + if (preg_match('{columns:\s*(\d+)}i', $this->getConsoleMode(), $matches)) { return $matches[1]; } } @@ -877,8 +876,7 @@ protected function getTerminalHeight() return preg_replace('{^\d+x\d+ \(\d+x(\d+)\)$}', '$1', trim($ansicon)); } - exec('mode CON', $execData); - if (preg_match('{lines:\s*(\d+)}i', $execData[3], $matches)) { + if (preg_match('{lines:\s*(\d+)}i', $this->getConsoleMode(), $matches)) { return $matches[1]; } } @@ -966,6 +964,29 @@ private function getSttyColumns() } } + /** + * Runs and parses mode CON if it's available, suppressing any error output + * + * @return string + */ + private function getConsoleMode() + { + if (!function_exists('proc_open')) { + return; + } + + $descriptorspec = array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')); + $process = proc_open('mode CON', $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. *