Skip to content

Commit

Permalink
[Console] Fix error when mode is not in PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Oct 15, 2012
1 parent 13e6ce4 commit cf1e02d
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/Symfony/Component/Console/Application.php
Expand Up @@ -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];
}
}
Expand All @@ -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];
}
}
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit cf1e02d

Please sign in to comment.