subprocess.Popen() is a little weird about when it closes the file
descriptors you give it. In this case, we have to dup() it because if
stderr=2 (the default) and stdout=2 (because fix_stderr), it'll close fd 2.
But if we dup it first, it *won't* close the dup, because stdout!=stderr.
So we have to dup it, but then we have to close it ourselves.
This was apparently harmless (it just resulted in an extra fd#3 getting
passed around to subprocesses as a clone of fd#2) but it was still wrong.
if fix_stdout or fix_stderr:
realf = fix_stderr and 2 or 1
+ drealf = os.dup(realf) # Popen goes crazy with stdout=2
n = subprocess.Popen([subpath('newliner')],
- stdin=subprocess.PIPE, stdout=os.dup(realf),
+ stdin=subprocess.PIPE, stdout=drealf,
close_fds=True, preexec_fn=force_tty)
+ os.close(drealf)
outf = fix_stdout and n.stdin.fileno() or None
errf = fix_stderr and n.stdin.fileno() or None
else: