[Console] Use proc_open instead of exec to suppress errors when run on windows and stty is not present
This commit is contained in:
parent
50eb170ead
commit
4f93d1addd
@ -800,7 +800,7 @@ class Application
|
|||||||
return preg_replace('{^(\d+)x.*$}', '$1', $ansicon);
|
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[2];
|
return $match[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -816,7 +816,7 @@ class Application
|
|||||||
return preg_replace('{^\d+x\d+ \(\d+x(\d+)\)$}', '$1', trim($ansicon));
|
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[1];
|
return $match[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -833,6 +833,25 @@ class Application
|
|||||||
return $input->getFirstArgument('command');
|
return $input->getFirstArgument('command');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Sorts commands in alphabetical order.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user