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