summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2013-08-08 16:51:00 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2013-08-08 16:51:00 +0000
commit93552afed2823d4c5481a240372999a36218ad8d (patch)
tree45c3f5ccc37727e26759e919b4bb817eeb77b8aa
parente280f1639c46e0f80fc3d779343486b74723a6d1 (diff)
downloadcliapp-baserock/richardmaw/cliapp-pipefail.tar.gz
runcmd: Fail if any command in a pipeline failsbaserock/richardmaw/cliapp-pipefail
This simulates bash's `set -o pipefail` option, so that the exit code of a pipeline is the last non-zero code.
-rw-r--r--cliapp/runcmd.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/cliapp/runcmd.py b/cliapp/runcmd.py
index 325b246..6304a48 100644
--- a/cliapp/runcmd.py
+++ b/cliapp/runcmd.py
@@ -210,7 +210,8 @@ def _run_pipeline(procs, feed_stdin, pipe_stdin, pipe_stdout, pipe_stderr):
if p.returncode is None:
p.wait()
- return procs[-1].returncode, ''.join(out), ''.join(err)
+ errorcodes = [p.returncode for p in procs if p.returncode != 0] or [0]
+ return errorcodes[-1], ''.join(out), ''.join(err)