0

Is there a way I can "redirect" stderr to stdout but continue to print stderr?

I can redirect stderr to stdout with

cmd 2>&1 | other_cmd

However, the above will no longer print the stderr from cmd onto my terminal. I would like to redirect it and see the logs on my terminal.

Note: I do NOT want to redirect to a file, therefore I don't think tee works for me.


Edit: it was pointed out that this is similar to How do I write standard error to a file while using "tee" with a pipe?

I would say that this is a simpler subset of that problem. Though they are similar, I think this question stands on its own due to the fact that most folks (me included) do not understand the intricacies of process substitution and file redirection. In particular, folks would have some difficulty with converting:

command > >(tee -a stdout.log) 2> >(tee -a stderr.log >&2)

Into the answer given here

cmd 2> >(tee /dev/tty) | other_cmd

Among other things, that answer does not use /dev/tty, which I did not know you could do!

vitiral
  • 8,446
  • 8
  • 29
  • 43
  • Does this answer your question? [redirect stderr and keep stdout](https://stackoverflow.com/questions/57431202/redirect-stderr-and-keep-stdout) – Gaurav Pathak Jan 14 '23 at 11:59

1 Answers1

3

In Bash

cmd 2> >(tee /dev/tty) | other_cmd

In any shell

{ { cmd 2>&1 >&3;} | tee /dev/tty;} 3>&1 | other_cmd
oguz ismail
  • 1
  • 16
  • 47
  • 69