From 890e26fbc6f8126c244185256f8a2b6ebc636505 Mon Sep 17 00:00:00 2001 From: Papoteur Date: Wed, 2 Dec 2015 20:24:06 +0100 Subject: Change the getstatusoutput function to not get error when reading special characters. --- MgaRepo/util.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'MgaRepo') diff --git a/MgaRepo/util.py b/MgaRepo/util.py index 70a8e85..2ffd1b4 100644 --- a/MgaRepo/util.py +++ b/MgaRepo/util.py @@ -18,13 +18,17 @@ import httplib2 # module directory, so we can't import Python's standard module def commands_getstatusoutput(cmd): """Return (status, output) of executing cmd in a shell.""" - import os - pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r') - text = pipe.read() - sts = pipe.close() - if sts is None: sts = 0 + pipe = subprocess.Popen('{ ' + cmd + '; } 2>&1', stdin = subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines = True, shell = True) + of = pipe.stdout.fileno() + text = '' + pipe.stdin.close() + while True: + text += os.read(of,8192).decode('utf8') + status = pipe.poll() + if status is not None or text == '': + break if text[-1:] == '\n': text = text[:-1] - return sts, text + return status, text def execcmd(*cmd, **kwargs): cmdstr = " ".join(cmd) -- cgit v1.2.1