From 50a5baa56961c2d98bbb3ee5b4cf1f0d2f230088 Mon Sep 17 00:00:00 2001 From: Chase Qi Date: Thu, 20 Oct 2016 10:17:05 +0800 Subject: 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 --- automated/lib/sh-test-lib | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'automated') 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" -- cgit v1.2.3