From 3afa0424b3804bf279a6b3f45af1ea2414c629e0 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Fri, 17 Jul 2020 23:26:40 +0530 Subject: [PATCH] [2.10] display: use stdout for column width (#70290) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit stdout may differ from stdin so it should be used to determine the column width, especially since it is the target file descriptor. (cherry picked from commit 45e0f747026c5b6e29b2a32c78785ff970da5655) Co-authored-by: Pavel Březina --- changelogs/fragments/display-stdout-column-width.yml | 2 ++ lib/ansible/utils/display.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/display-stdout-column-width.yml diff --git a/changelogs/fragments/display-stdout-column-width.yml b/changelogs/fragments/display-stdout-column-width.yml new file mode 100644 index 00000000000..da0febc2230 --- /dev/null +++ b/changelogs/fragments/display-stdout-column-width.yml @@ -0,0 +1,2 @@ +bugfixes: + - Ansible output now uses stdout to determine column width instead of stdin diff --git a/lib/ansible/utils/display.py b/lib/ansible/utils/display.py index 3943522af8a..0eba8aa37ce 100644 --- a/lib/ansible/utils/display.py +++ b/lib/ansible/utils/display.py @@ -430,8 +430,8 @@ class Display(with_metaclass(Singleton, object)): return encoding def _set_column_width(self): - if os.isatty(0): - tty_size = unpack('HHHH', fcntl.ioctl(0, TIOCGWINSZ, pack('HHHH', 0, 0, 0, 0)))[1] + if os.isatty(1): + tty_size = unpack('HHHH', fcntl.ioctl(1, TIOCGWINSZ, pack('HHHH', 0, 0, 0, 0)))[1] else: tty_size = 0 self.columns = max(79, tty_size - 1)