title: Process connected to separate pty for stdout and stderr
body: <p>I'm writing a <a href="https://github.com/nc6/tabula" rel="nofollow noreferrer">terminal logging program</a> - think the <code>script</code> command but a bit more featureful. One of the differences is that, whereas <code>script</code> captures stdout, stdin and stderr as one big character stream, I would like to keep them separate and record them as such.</p>
  <p>In order to do this, I use the standard approach of running a child shell connected to a pty, but instead of using a single pty with stdin, stdout and stderr all connected to it, I use two ptys - with stdin and stderr connected to one pty, and stdout on the other. This way, the master process can tell what is coming from stdout and what from stderr.</p>
  <p>This has, so far, worked fine. However, I'm starting to run into a few issues. For example, when trying to set the number of columns, I get the following:</p>
  <blockquote>
  <p>$stty cols 169</p>
  <p>stty: stdout appears redirected, but stdin is the control descriptor</p>
  </blockquote>
  <p>This seems to be a result of <a href="http://src.gnu-darwin.org/src/bin/stty/util.c" rel="nofollow noreferrer">this piece of code</a>, which seems to check whether stdout and stderr are both ttys, but complains if they are not the same.</p>
  <p>My question, therefore, is this: am I violating any fundamental assumptions about how Posix processes behave by acting in this way? If not, any idea why I'm seeing errors such as this? If so, is there any way I can get around this and still manage to separate stdout and stderr nicely?</p>