#!/bin/sh
#
# err-to-stderr - fix programs that output err messages on stdout (instead of stderr)
#
# usage: err-to-stderr CMD
# executes CMD. if exit value is 0, send output to stdout, otherwise to stderr

tmp=$(mktemp)

if "$@" >"${tmp}"; then
  cat "${tmp}"
else
  cat "${tmp}" >&2
fi

rm -- "${tmp}"
