From 34b3db242f9076d68f20fdeb188836dee690d9a3 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 28 Feb 2014 21:45:59 +0100 Subject: add spawn_read MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/util.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/util.py b/src/util.py index 25aac1f..e95c419 100644 --- a/src/util.py +++ b/src/util.py @@ -58,3 +58,16 @@ def spawn(*command): proc = subprocess.Popen(list(command), stderr = sys.stderr, stdout = subprocess.PIPE) return proc.stdout + +def spawn_read(*command): + ''' + Spawn an external process and returns its output + + @param command:*str The command line + @return :str The process's output to stdout, without the final LF + ''' + proc = subprocess.Popen(list(command), stderr = sys.stderr, stdout = subprocess.PIPE) + out = proc.stdout.read().decode('utf-8', 'replace') + if out.endswith('\n'): + out = out[:-1] + return out -- cgit v1.2.3-70-g09d2