From 88f514c956b304407a2426f3da0918673602e3ee Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Wed, 20 Mar 2019 03:36:20 -0400 Subject: Only capturing Popen output when stdout is a StdSim object --- cmd2/utils.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'cmd2/utils.py') diff --git a/cmd2/utils.py b/cmd2/utils.py index dd71cfc2..a0026eba 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -371,9 +371,9 @@ class ByteBuf(object): class ProcReader(object): - """Used to read stdout and stderr from a process whose stdout and stderr are set to binary pipes""" - def __init__(self, proc: subprocess.Popen, stdout: Union[BinaryIO, TextIO], - stderr: Union[BinaryIO, TextIO]) -> None: + """Used to read stdout and stderr from a Popen process whose stdout and stderr are set to binary pipes""" + def __init__(self, proc: subprocess.Popen, stdout: Union[StdSim, BinaryIO, TextIO], + stderr: Union[StdSim, BinaryIO, TextIO]) -> None: """ ProcReader initializer :param proc: the Popen process being read from @@ -394,6 +394,10 @@ class ProcReader(object): self._out_thread.start() self._err_thread.start() + def terminate(self) -> None: + """Terminates the process being run""" + self._proc.terminate() + def wait(self) -> None: """Wait for the process to finish""" self._out_thread.join() @@ -427,7 +431,7 @@ class ProcReader(object): self._write_bytes(write_stream, available) @staticmethod - def _write_bytes(stream: Union[BinaryIO, TextIO], to_write: bytes) -> None: + def _write_bytes(stream: Union[StdSim, BinaryIO, TextIO], to_write: bytes) -> None: """ Write bytes to a stream :param stream: the stream being written to -- cgit v1.2.1