How to create an additional terminal-based output stream?

Viewed 23

How would I create an additional file descriptor that connects to the terminal for debug messages? I'd like something just like standard out/error streams (stdout/stderr). For clarity sake, I'll call this new stream spdbg (for "special debug"). I thought about using dup() to duplicate the stdout/stderr stream, but if that stream gets redirected to a file then that means spdbg also gets redirected to the same file, which I don't want. Instead, I'd like spdbg to redirect to the terminal, just like stdout/stderr initially do. In other words, if stdout/stderr gets redirected to a file, then spdbg should still point to the terminal. However, spdbg can still be redirected to a file, if the user wishes to do so.

0 Answers
Related