From f7ac0123011a21ce8282fb5450a3799572f15a14 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Sun, 14 Dec 2014 17:56:18 +0100 Subject: [PATCH 1/2] Do not assume that stdin is a tty This can be used from another non interactive software, see #9695 for details. --- bin/ansible-doc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/ansible-doc b/bin/ansible-doc index 0ba84b9a305..59d14b6ef14 100755 --- a/bin/ansible-doc +++ b/bin/ansible-doc @@ -165,7 +165,10 @@ def get_snippet_text(doc): return "\n".join(text) def get_module_list_text(module_list): - columns = max(60, int(os.popen('stty size', 'r').read().split()[1])) + tty_size = 0 + if os.isatty(0): + tty_size = int(os.popen('stty size', 'r').read().split()[1]) + columns = max(60, tty_size) displace = max(len(x) for x in module_list) linelimit = columns - displace - 5 text = [] From caefc20f160e2dece37d883fea98c94f5bd89379 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Sun, 14 Dec 2014 18:09:42 +0100 Subject: [PATCH 2/2] Use --version to see if less can be executed (less) 2> /dev/null would fail if stdin is /dev/null. Sinceless --version do not read anything from stdin, it is perfect for seeing if the software exist or not. Also replace the whole os system detection by directly using subprocess ( as we use it elsewhere, we already depend on it ). --- bin/ansible-doc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/ansible-doc b/bin/ansible-doc index 59d14b6ef14..36db3dff42d 100755 --- a/bin/ansible-doc +++ b/bin/ansible-doc @@ -71,7 +71,7 @@ def pager(text): pager_print(text) else: pager_pipe(text, os.environ['PAGER']) - elif hasattr(os, 'system') and os.system('(less) 2> /dev/null') == 0: + elif subprocess.call('(less --version) 2> /dev/null', shell = True) == 0: pager_pipe(text, 'less') else: pager_print(text)