##// END OF EJS Templates
Allow pexpect piped processes to work with either pexpect-u or vanilla pexpect.
Thomas Kluyver -
Show More
@@ -147,13 +147,17 b' class ProcessHandler(object):'
147 # can set pexpect's search window to be tiny and it won't matter.
147 # can set pexpect's search window to be tiny and it won't matter.
148 # We only search for the 'patterns' timeout or EOF, which aren't in
148 # We only search for the 'patterns' timeout or EOF, which aren't in
149 # the text itself.
149 # the text itself.
150 child = pexpect.spawn(self.sh, args=['-c', cmd], encoding=enc)
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:
154 child = pexpect.spawn(self.sh, args=['-c', cmd]) # Vanilla Pexpect
151 flush = sys.stdout.flush
155 flush = sys.stdout.flush
152 while True:
156 while True:
153 # res is the index of the pattern that caused the match, so we
157 # res is the index of the pattern that caused the match, so we
154 # know whether we've finished (if we matched EOF) or not
158 # know whether we've finished (if we matched EOF) or not
155 res_idx = child.expect_list(patterns, self.read_timeout)
159 res_idx = child.expect_list(patterns, self.read_timeout)
156 print(child.before[out_size:], end='')
160 print(py3compat.cast_unicode(child.before[out_size:], enc), end='')
157 flush()
161 flush()
158 if res_idx==EOF_index:
162 if res_idx==EOF_index:
159 break
163 break
@@ -169,7 +173,7 b' class ProcessHandler(object):'
169 try:
173 try:
170 out_size = len(child.before)
174 out_size = len(child.before)
171 child.expect_list(patterns, self.terminate_timeout)
175 child.expect_list(patterns, self.terminate_timeout)
172 print(child.before[out_size:], end='')
176 print(py3compat.cast_unicode(child.before[out_size:], enc), end='')
173 sys.stdout.flush()
177 sys.stdout.flush()
174 except KeyboardInterrupt:
178 except KeyboardInterrupt:
175 # Impatient users tend to type it multiple times
179 # Impatient users tend to type it multiple times
General Comments 0
You need to be logged in to leave comments. Login now