Revision 12799
Added by Aaron Marcuse-Kubitza almost 11 years ago
trunk/lib/sh/util.sh | ||
---|---|---|
783 | 783 |
# usage: { stderr2stdout cmd|stdout_contains echo_run grep ...; } 41>&1 |
784 | 784 |
{ echo_func; pipe_delay; pipe_delay; pipe_delay; "$@"|echo_stdout >/dev/null; } |
785 | 785 |
|
786 |
stderr_matches() # wrapper usage: pattern=... [ignore_e=#] stderr_matches cmd... |
|
787 |
# wrapper caller usage: prep_try; if [!] wrapper; then rethrow; ...; fi; rethrow |
|
788 |
# OR prep_try; wrapper || { rethrow; ...; }; rethrow |
|
789 |
# exit status of cmd is placed in $e for use with exception handling |
|
786 |
stderr_matches() # usage: pattern=... [ignore_e=#] stderr_matches cmd... |
|
790 | 787 |
{ |
791 | 788 |
echo_func; kw_params pattern ignore_e; : "${pattern?}" |
792 | 789 |
if test "$ignore_e"; then local benign_error=1; fi |
793 | 790 |
|
791 |
# not necessary to allow callers to handle the error themselves (which would |
|
792 |
# require *every* caller to wrap this function in prep_try/rethrow), because |
|
793 |
# they would just handle it by errexiting anyways |
|
794 |
prep_try |
|
795 |
|
|
794 | 796 |
set +o errexit # avoid errexiting since @PIPESTATUS will be used instead |
795 | 797 |
{ stderr2stdout "$@"|stdout_contains echo_run grep -E "$pattern"; } 41>&1 |
796 | 798 |
local PIPESTATUS_=("${PIPESTATUS[@]}") # save b/c it's reset after each cmd |
797 | 799 |
set -o errexit |
798 | 800 |
|
801 |
# handle any error |
|
799 | 802 |
e="${PIPESTATUS_[0]}" # 1st command's exit status -> $e |
800 | 803 |
ignore_e "$ignore_e" # also works w/ ignore_e='' |
804 |
rethrow_exit |
|
805 |
|
|
801 | 806 |
return "${PIPESTATUS_[1]}" # 2nd command's exit status -> $? |
802 | 807 |
} |
803 | 808 |
|
Also available in: Unified diff
lib/sh/util.sh: stderr_matches(): moved prep_try/rethrow into the function itself so that callers don't have to wrap this function in a complex sequence of prep_try/rethrow statements