Say I have 3 commands linked through pipes:
A | B | C
I would like B to output error messages to stderr and some progress to the terminal. If stderr is the same as the terminal, then that is easy: Simply send the progress information to stderr. But what if stderr is redirected?
A | B 2>/tmp/file | C
Then I still want the progress information to go to the terminal, while error messages go to the file.
Can I now somehow identify the terminal that stderr would have ended up on had it not been redirected?
My initial idea would be to find the tty using tty and then opening that and writing to it. However, if I call tty from inside B tty says: not a tty, which I believe is because of the pipe between A and B.
I would like to do this from Perl.