]> arthur.barton.de Git - bup.git/commitdiff
helpers.py: check subprocess exit status in readpipe().
authorRob Browning <rlb@defaultvalue.org>
Sun, 23 Mar 2014 22:52:59 +0000 (17:52 -0500)
committerRob Browning <rlb@defaultvalue.org>
Fri, 2 May 2014 15:57:35 +0000 (10:57 -0500)
Checking the exit status seems like a good idea.  Note that we can't
just use check_output() because it wasn't added until Python 2.7.

Thanks to Alexander Barton <alex@barton.de> for reporting the version
incompatibility with respect to an earlier version of this patch.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/helpers.py

index a169196ba89f3923aed29c1e9e90adaf46cbddfe..a56f656d988df1207c53f73ec50087ff04df0f1b 100644 (file)
@@ -180,9 +180,11 @@ def unlink(f):
 def readpipe(argv):
     """Run a subprocess and return its output."""
     p = subprocess.Popen(argv, stdout=subprocess.PIPE)
-    r = p.stdout.read()
-    p.wait()
-    return r
+    out, err = p.communicate()
+    if p.returncode != 0:
+        raise Exception('subprocess %r failed with status %d'
+                        % (' '.join(argv), p.retcode))
+    return out
 
 
 def realpath(p):