how do i set the virtual terminal size with shell_exec() ? i tried
function shell_exec_with_size(string $cmd, int $columns = 999, int $rows = 999): string
{
$cmd = '/bin/bash -c ' . escapeshellarg("stty columns {$columns}; stty rows {$rows};{$cmd}");
return shell_exec($cmd);
}
but that seems to have no effect, at least the columns property wasn’t actually applied (don’t know if the rows property was set or not)..
having a problem with yum check-updates
changing the format depending on column size, with a "small" column size and a long update name, the format is
python-devel.x86_64 2.7.18-1.amzn2.0.5 amzn2-core
python-libs.x86_64 2.7.18-1.amzn2.0.5 amzn2-core
python-pillow.x86_64 2.0.0-23.gitd1c6db8.amzn2.0.1
amzn2-core
(where python-pillow’s update name 2.0.0-23.gitd1c6db8.amzn2.0.1
is too long), but with a large terminal size it’s instead printed as
python.x86_64 2.7.18-1.amzn2.0.5 amzn2-core
python-devel.x86_64 2.7.18-1.amzn2.0.5 amzn2-core
python-libs.x86_64 2.7.18-1.amzn2.0.5 amzn2-core
python-pillow.x86_64 2.0.0-23.gitd1c6db8.amzn2.0.1 amzn2-core
python2-rpm.x86_64 4.11.3-48.amzn2.0.2 amzn2-core
and im trying to parse the list programmatically, so specifying the terminal size would help get a consistent format from yum check-updates
… also i have checked if yum perhaps separates the properties with tabs or something: it doesn’t. it just seem to separate the properties with spaces, or newline and spaces, depending on terminal size.
2
Answers
... don't know why, but using util-linux's
script
command instead of bash makes stty functional, combiningscript --command 'stty columns 999;cmd' /dev/null
works:(i also suspect, but haven't confirmed, that
script
calls/bin/sh
behind-the-scene)An alternate approach is to pipe it out to a file and then read it back with
file_get_contents
EDIT: Although now that I think about it, I’m not sure how
yum
will play with being piped to a file. Can you look in/var/log/yum
instead?Then with
test.sh
Outputs: