From d7b3c45d43f1a44c146e87830f50c1f2b63c220c Mon Sep 17 00:00:00 2001 From: Papoteur Date: Thu, 16 May 2024 15:03:21 +0200 Subject: Fix reading from command output, could crash when chunks are cut at middle of an unicode character. --- MgaRepo/util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MgaRepo/util.py b/MgaRepo/util.py index 6d31399..635319d 100644 --- a/MgaRepo/util.py +++ b/MgaRepo/util.py @@ -20,15 +20,15 @@ def commands_getstatusoutput(cmd): """Return (status, output) of executing cmd in a shell.""" pipe = subprocess.Popen('{ ' + cmd + '; } 2>&1', stdin = subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines = True, shell = True) of = pipe.stdout.fileno() - text = '' + text = b'' pipe.stdin.close() while True: - text += os.read(of,8192).decode('utf8') + text += os.read(of,8192) status = pipe.poll() if status is not None or text == '': break if text[-1:] == '\n': text = text[:-1] - return status, text + return status, text.decode('utf8') def execcmd(*cmd, **kwargs): cmdstr = " ".join(cmd) -- cgit v1.2.1