summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott <[email protected]>2022-01-19 14:10:35 -0800
committerScott <[email protected]>2022-01-19 14:10:35 -0800
commitf9a44edcbc221df7965d23313c0b3daca20775ad (patch)
tree1b5eef39807bdccf75c16a9d1bd4c2bad0ee3453
parent1315e2d5356aa3616ef96ded72b7902c8591ebd7 (diff)
Make cmd_showing_output work with subprocesses that use '\r'.
-rw-r--r--exec_utils.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/exec_utils.py b/exec_utils.py
index b52f52f..36d48fa 100644
--- a/exec_utils.py
+++ b/exec_utils.py
@@ -4,6 +4,7 @@ import atexit
import logging
import shlex
import subprocess
+import sys
from typing import List, Optional
@@ -11,16 +12,19 @@ logger = logging.getLogger(__file__)
def cmd_showing_output(command: str) -> None:
+ line_enders = set([b'\n', b'\r'])
p = subprocess.Popen(
command,
shell=True,
bufsize=0,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
+ universal_newlines=False,
)
- for line in iter(p.stdout.readline, b''):
- print(line.decode('utf-8'), end='')
- p.stdout.close()
+ for char in iter(lambda: p.stdout.read(1), b''):
+ sys.stdout.buffer.write(char)
+ if char in line_enders:
+ sys.stdout.flush()
p.wait()