diff options
author | Chase Qi <chase.qi@linaro.org> | 2016-10-20 10:17:05 +0800 |
---|---|---|
committer | Milosz Wasilewski <milosz.wasilewski@linaro.org> | 2016-10-20 09:48:06 +0000 |
commit | 50a5baa56961c2d98bbb3ee5b4cf1f0d2f230088 (patch) | |
tree | c6c1f0de3bb577476f29c80b828a605c97e94f40 | |
parent | bc262f5c23355b814d89494c940292ca87f3f943 (diff) |
v2: lib: add pipe0_status function
pipe0_status is used to return exit code of the first command when using
pipe. Usage: pipe0_status "cmd1" "cmd2"
Change-Id: I1549e807c2a5401fdc1435a4ac3ac06e27765663
Signed-off-by: Chase Qi <chase.qi@linaro.org>
-rwxr-xr-x | automated/lib/sh-test-lib | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/automated/lib/sh-test-lib b/automated/lib/sh-test-lib index 39a7e92..44f59fe 100755 --- a/automated/lib/sh-test-lib +++ b/automated/lib/sh-test-lib @@ -143,6 +143,20 @@ install_deps() { fi } +# Return the exit code of the first command when using pipe. +pipe0_status() { + [ "$#" -ne 2 ] && error_msg "Usage: pipe0_status cmd1 cmd2" + local cmd1="$1" + local cmd2="$2" + + exec 4>&1 + ret_val=$({ { eval "${cmd1}" 3>&-; echo "$?" 1>&3; } 4>&- \ + | eval "${cmd2}" 1>&4; } 3>&1) + exec 4>&- + + return "${ret_val}" +} + validate_check_sum() { if [ "$#" -ne 2 ]; then warn_msg "The number of parameters should be 2" |