aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-02-28 21:45:59 +0100
committerMattias Andrée <maandree@operamail.com>2014-02-28 21:45:59 +0100
commit34b3db242f9076d68f20fdeb188836dee690d9a3 (patch)
tree5da7ee658abd3f67b95a04dda14e49ec6e021f85 /src/util.py
parentfix special chars (diff)
downloadxpybar-34b3db242f9076d68f20fdeb188836dee690d9a3.tar.gz
xpybar-34b3db242f9076d68f20fdeb188836dee690d9a3.tar.bz2
xpybar-34b3db242f9076d68f20fdeb188836dee690d9a3.tar.xz
add spawn_read
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/util.py')
-rw-r--r--src/util.py13
1 files changed, 13 insertions, 0 deletions
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