summaryrefslogtreecommitdiff
path: root/cmd2/utils.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-03-20 01:13:36 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-03-20 01:13:36 -0400
commit66faf90bc5551066a207dbd78ad8dd2297f53474 (patch)
treedcd1ff7e54d368ca7f4e9cb53091e67fb28c2de7 /cmd2/utils.py
parentd7008b7b6ba9a5020fb32cea97161b89dfba0dc3 (diff)
downloadcmd2-git-66faf90bc5551066a207dbd78ad8dd2297f53474.tar.gz
Fixed issue where remaining bytes were not being read
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r--cmd2/utils.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py
index 310f0284..dd71cfc2 100644
--- a/cmd2/utils.py
+++ b/cmd2/utils.py
@@ -399,6 +399,13 @@ class ProcReader(object):
self._out_thread.join()
self._err_thread.join()
+ # Handle case where the process ended before the last read could be done
+ out, err = self._proc.communicate()
+ if out:
+ self._write_bytes(self._stdout, out)
+ if err:
+ self._write_bytes(self._stderr, err)
+
def _reader_thread_func(self, read_stdout: bool) -> None:
"""
Thread function that reads a stream from the process
@@ -416,15 +423,8 @@ class ProcReader(object):
# noinspection PyUnresolvedReferences
available = read_stream.peek()
if available:
- out = read_stream.read(len(available))
- self._write_bytes(write_stream, out)
-
- # Handle case where the process ended before the last could be done
- # noinspection PyUnresolvedReferences
- available = read_stream.peek()
- if available:
- out = read_stream.read(len(available))
- self._write_bytes(write_stream, out)
+ read_stream.read(len(available))
+ self._write_bytes(write_stream, available)
@staticmethod
def _write_bytes(stream: Union[BinaryIO, TextIO], to_write: bytes) -> None: