From 802df205b23bec291959ef495328637a1a786f2e 2019-11-17 17:46:02 From: Matthias Bussonnier Date: 2019-11-17 17:46:02 Subject: [PATCH] Use proper subprocess commands instead of modifying the command line. This should in particular work on windows; as 2>/dev/null might not have been proper windows syntax --- diff --git a/IPython/core/page.py b/IPython/core/page.py index cf9fb21..afdded2 100644 --- a/IPython/core/page.py +++ b/IPython/core/page.py @@ -15,9 +15,11 @@ rid of that dependency, we could move it there. import os +import io import re import sys import tempfile +import subprocess from io import UnsupportedOperation @@ -208,9 +210,13 @@ def pager_page(strng, start=0, screen_lines=0, pager_cmd=None): else: try: retval = None - # if I use popen4, things hang. No idea why. - #pager,shell_out = os.popen4(pager_cmd) - pager = os.popen(pager_cmd + ' 2>/dev/null', 'w') + # Emulate os.popen, but redirect stderr + proc = subprocess.Popen(pager_cmd, + shell=True, + stdin=subprocess.PIPE, + stderr=subprocess.DEVNULL + ) + pager = os._wrap_close(io.TextIOWrapper(proc.stdin), proc) try: pager_encoding = pager.encoding or sys.stdout.encoding pager.write(strng)