Project

General

Profile

« Previous | Next » 

Revision 12762

lib/sh/util.sh: stderr_matches(): supporting ignoring any benign error exit status associated with the error message being tested for

View differences:

trunk/lib/sh/util.sh
779 779
# usage: { stderr2stdout cmd|stdout_contains echo_run grep ...; } 41>&1
780 780
{ echo_func; pipe_delay; pipe_delay; pipe_delay; "$@"|echo_stdout >/dev/null; }
781 781

  
782
stderr_matches() # usage: prep_try; if pattern=... "stderr_matches" cmd...; \
783
# then ...; fi; [ignore_e #;] rethrow # rethrow any command error, if applicable
782
stderr_matches() # usage: prep_try; if pattern=... [ignore_e=#] \
783
# "stderr_matches" cmd...; then ...; fi; rethrow # rethrow any command error
784 784
# exit status of cmd is placed in $e for use with exception handling
785 785
{
786
	echo_func; kw_params pattern; : "${pattern?}"
786
	echo_func; kw_params pattern ignore_e; : "${pattern?}"
787 787
	
788 788
	set +o errexit # avoid errexiting since @PIPESTATUS will be used instead
789 789
	{ stderr2stdout "$@"|stdout_contains echo_run grep -E "$pattern"; } 41>&1
......
791 791
	set -o errexit
792 792
	
793 793
	e="${PIPESTATUS_[0]}"      # 1st command's exit status -> $e
794
	ignore_e "$ignore_e" # also works w/ ignore_e=''
794 795
	return "${PIPESTATUS_[1]}" # 2nd command's exit status -> $?
795 796
}
796 797

  

Also available in: Unified diff