Skip to content
Snippets Groups Projects

fix output handling for subprocesses with multi-byte chars

1 file
+ 8
7
Compare changes
  • Side-by-side
  • Inline
+ 8
7
@@ -128,16 +128,17 @@ class TestRun:
def cmd_live_log(self, log_file, *cmd, cwd=None) -> bool:
if cwd is None:
cwd = self.main_dir
with open(log_file, "wb") as log:
with subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, cwd=cwd) as proc:
with open(log_file, "wb") as log, \
io.TextIOWrapper(log, encoding='utf8') as logger, \
subprocess.Popen(cmd, stdout=subprocess.PIPE, \
stderr=subprocess.STDOUT, cwd=cwd) as proc, \
io.TextIOWrapper(proc.stdout, encoding='utf8') as reader:
while True:
output = proc.stdout.read(1)
output = reader.read(1)
if not output:
break
print(output.decode("utf-8"), end='')
log.write(output)
print(output, end='')
logger.write(output)
return proc.returncode == 0
def log(self, msg, stage=None):
Loading