diff options
author | Papoteur <papoteur@mageialinux-online.org> | 2015-12-02 20:24:06 +0100 |
---|---|---|
committer | Papoteur <papoteur@mageialinux-online.org> | 2015-12-02 20:24:06 +0100 |
commit | 890e26fbc6f8126c244185256f8a2b6ebc636505 (patch) | |
tree | 8ad3153e68b2975fd52a5f585b8f6c7b92ac57ff /MgaRepo | |
parent | 2453721abe41885e8c428abd14890380ab9157ee (diff) | |
download | mgarepo-890e26fbc6f8126c244185256f8a2b6ebc636505.tar mgarepo-890e26fbc6f8126c244185256f8a2b6ebc636505.tar.gz mgarepo-890e26fbc6f8126c244185256f8a2b6ebc636505.tar.bz2 mgarepo-890e26fbc6f8126c244185256f8a2b6ebc636505.tar.xz mgarepo-890e26fbc6f8126c244185256f8a2b6ebc636505.zip |
Change the getstatusoutput function to not get error when reading special characters.
Diffstat (limited to 'MgaRepo')
-rw-r--r-- | MgaRepo/util.py | 16 |
1 files changed, 10 insertions, 6 deletions
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) |