Skip to content

Commit

Permalink
Fix broken pipe errors
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-schulze-vireso committed Jan 31, 2023
1 parent ad3b159 commit e82402f
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions libexec/bats-core/bats
Original file line number Diff line number Diff line change
Expand Up @@ -485,16 +485,7 @@ bats_tee() { # <output-file> <command...>
local output_file=$1 status=0
shift
exec 3<&1 # use FD3 to get around pipe
{
while IFS= read -r line; do
printf "%s\n" "$line" || exit 1 # write to command/file
printf "%s\n" "$line" >&3 # write to our stdout
done
if [[ -n "$line" ]]; then
printf "%s\n" "$line" # write to command/file
printf "%s\n" "$line" >&3 # write to our stdout
fi
} | "$@" >"$output_file" || status=$?
tee >(cat >&3) | "$@" >"$output_file" || status=$?
if (( status != 0 )); then
printf "ERROR: command \`%s\` failed with status %d\n" "$*" "$status" >&2
fi
Expand Down

0 comments on commit e82402f

Please sign in to comment.