Project

General

Profile

« Previous | Next » 

Revision 12209

bugfix: lib/sh/util.sh: stderr_matches(): need to avoid redirecting stderr and stdout to the same place, because this prevents redirecting stdout back to the original stdout after stderr has been filtered using |

View differences:

util.sh
704 704
}
705 705
alias filter_fd='"filter_fd" ' # last space alias-expands next word
706 706

  
707
stderr2stdout() # usage: stderr2stdout cmd... # unlike `2>&1`, logs stderr
707
stderr2stdout() # usage: { stderr2stdout cmd...|use stderr...; } 41>&1
708
# **IMPORTANT**: fd 41 must later be redirected back to fd 1
709
# unlike `2>&1`, logs stderr
710
# redirects the command stdout to fd 41 to avoid collision with stderr
708 711
{
709 712
	echo_func
710 713
	# command causes log_fd to be re-filtered, so that stderr is also filtered.
711 714
	# this allows log-filtering out an otherwise-confusing benign error.
712
	"$@" 2> >(command tee /dev/fd/"$log_fd") # redirects 2->1,log_fd (*not* ->2)
715
	"$@" 2> >(command tee /dev/fd/"$log_fd") >&41
716
		# redirects 2->{1,log_fd} (*not* ->2)
713 717
}
714 718

  
715 719
stdout_contains() # usage: stderr2stdout cmd|stdout_contains echo_run grep ...
......
720 724
# exit status of cmd is placed in $e for use with exception handling
721 725
{
722 726
	echo_func; kw_params pattern; : "${pattern?}"
723
	"try" stderr2stdout "$@"|"try" stdout_contains echo_run grep -E "$pattern"
727
	{ "try" stderr2stdout "$@"|"try" stdout_contains echo_run grep -E "$pattern"
728
	} 41>&1
724 729
	local PIPESTATUS_=("${PIPESTATUS[@]}") # save b/c it's reset after each cmd
725 730
	e="${PIPESTATUS_[0]}"      # 1st command's exit status -> $e
726 731
	return "${PIPESTATUS_[1]}" # 2nd command's exit status -> $?

Also available in: Unified diff