Show More
@@ -19,17 +19,12 from __future__ import print_function | |||
|
19 | 19 | import subprocess as sp |
|
20 | 20 | import sys |
|
21 | 21 | |
|
22 | # Third-party | |
|
23 | # We ship our own copy of pexpect (it's a single file) to minimize dependencies | |
|
24 | # for users, but it's only used if we don't find the system copy. | |
|
25 | try: | |
|
26 | import pexpect | |
|
27 | except ImportError: | |
|
28 | from IPython.external import pexpect | |
|
22 | from IPython.external import pexpect | |
|
29 | 23 | |
|
30 | 24 | # Our own |
|
31 | 25 | from .autoattr import auto_attr |
|
32 | 26 | from ._process_common import getoutput |
|
27 | from IPython.utils import text | |
|
33 | 28 | |
|
34 | 29 | #----------------------------------------------------------------------------- |
|
35 | 30 | # Function definitions |
@@ -132,6 +127,9 class ProcessHandler(object): | |||
|
132 | 127 | ------- |
|
133 | 128 | int : child's exitstatus |
|
134 | 129 | """ |
|
130 | # Get likely encoding for the output. | |
|
131 | enc = text.getdefaultencoding() | |
|
132 | ||
|
135 | 133 | pcmd = self._make_cmd(cmd) |
|
136 | 134 | # Patterns to match on the output, for pexpect. We read input and |
|
137 | 135 | # allow either a short timeout or EOF |
@@ -155,7 +153,7 class ProcessHandler(object): | |||
|
155 | 153 | # res is the index of the pattern that caused the match, so we |
|
156 | 154 | # know whether we've finished (if we matched EOF) or not |
|
157 | 155 | res_idx = child.expect_list(patterns, self.read_timeout) |
|
158 | print(child.before[out_size:], end='') | |
|
156 | print(child.before[out_size:].decode(enc, 'replace'), end='') | |
|
159 | 157 | flush() |
|
160 | 158 | if res_idx==EOF_index: |
|
161 | 159 | break |
@@ -171,7 +169,7 class ProcessHandler(object): | |||
|
171 | 169 | try: |
|
172 | 170 | out_size = len(child.before) |
|
173 | 171 | child.expect_list(patterns, self.terminate_timeout) |
|
174 | print(child.before[out_size:], end='') | |
|
172 | print(child.before[out_size:].decode(enc, 'replace'), end='') | |
|
175 | 173 | sys.stdout.flush() |
|
176 | 174 | except KeyboardInterrupt: |
|
177 | 175 | # Impatient users tend to type it multiple times |
General Comments 0
You need to be logged in to leave comments.
Login now