Make sure readline has been imported before duping any stdio handles--otherwise pyreadline fails to connect to the correct handle for the console's stdout/in.

This commit is contained in:
Erik M. Bray 2015-12-24 14:56:57 -05:00
parent cd3a441304
commit 924a9667e1
1 changed files with 8 additions and 0 deletions

View File

@ -308,6 +308,14 @@ class FDCapture:
""" Capture IO to/from a given os-level filedescriptor. """ """ Capture IO to/from a given os-level filedescriptor. """
def __init__(self, targetfd, tmpfile=None): def __init__(self, targetfd, tmpfile=None):
# ensure readline is imported so that it attaches to the correct
# stdio handles on Windows
if targetfd in (0, 1, 2):
try:
import readline
except ImportError:
pass
self.targetfd = targetfd self.targetfd = targetfd
try: try:
self.targetfd_save = os.dup(self.targetfd) self.targetfd_save = os.dup(self.targetfd)