##// END OF EJS Templates
Handle subprocesses more consistently between pexpect and pexpect-u.
Thomas Kluyver -
Show More
@@ -88,7 +88,7 b' support it. Pexpect is intended for UNIX-like operating systems.""")'
88 88 __version__ = '2.6.dev'
89 89 version = __version__
90 90 version_info = (2,6,'dev')
91 __all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn', 'run', 'which',
91 __all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn', 'spawnb', 'run', 'which',
92 92 'split_command_line', '__version__']
93 93
94 94 # Exception classes used by this module.
@@ -148,16 +148,16 b' class ProcessHandler(object):'
148 148 # We only search for the 'patterns' timeout or EOF, which aren't in
149 149 # the text itself.
150 150 #child = pexpect.spawn(pcmd, searchwindowsize=1)
151 try:
152 child = pexpect.spawn(self.sh, args=['-c', cmd], encoding=enc) # Pexpect-U
153 except TypeError:
151 if hasattr(pexpect, 'spawnb'):
152 child = pexpect.spawnb(self.sh, args=['-c', cmd]) # Pexpect-U
153 else:
154 154 child = pexpect.spawn(self.sh, args=['-c', cmd]) # Vanilla Pexpect
155 155 flush = sys.stdout.flush
156 156 while True:
157 157 # res is the index of the pattern that caused the match, so we
158 158 # know whether we've finished (if we matched EOF) or not
159 159 res_idx = child.expect_list(patterns, self.read_timeout)
160 print(py3compat.cast_unicode(child.before[out_size:], enc), end='')
160 print(child.before[out_size:].decode(enc, 'replace'), end='')
161 161 flush()
162 162 if res_idx==EOF_index:
163 163 break
@@ -173,7 +173,7 b' class ProcessHandler(object):'
173 173 try:
174 174 out_size = len(child.before)
175 175 child.expect_list(patterns, self.terminate_timeout)
176 print(py3compat.cast_unicode(child.before[out_size:], enc), end='')
176 print(child.before[out_size:].decode(enc, 'replace'), end='')
177 177 sys.stdout.flush()
178 178 except KeyboardInterrupt:
179 179 # Impatient users tend to type it multiple times
General Comments 0
You need to be logged in to leave comments. Login now