Skip to main content
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266
Source Link
oblitum
  • 1k
  • 16
  • 31

Print stderr only if nothing gets written to stdout, otherwise print just stdout discarding stderr

There's a command that always prints stuff to stderr. Such information is never useful except when it doesn't write anything to stdout.

So, is there a simple shell way, tool or command to help filtering stdout and stderr coming from the command and pipe them such that former stderr output is printed to stderr only if former stdout output is empty, otherwise (when stdout is not empty) it just prints stdout?