This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kr
Recipients kr
Date 2010-06-24.20:12:14
SpamBayes Score 4.869367e-07
Marked as misclassified No
Message-id <1277410336.39.0.223644435027.issue9074@psf.upfronthosting.co.za>
In-reply-to
Content
Transcript to reproduce in Python 2.6.5:

>>> import subprocess, sys
>>> subprocess.call(('echo', 'foo'), stderr=sys.stdout)
echo: write: Bad file descriptor
1
>>> 

Expected behavior:

>>> import subprocess, sys
>>> subprocess.call(('echo', 'foo'), stderr=sys.stdout)
foo
0
>>> 

This happens because we've asked the child's stderr to be redirected, but not its stdout. So in _execute_child, errwrite is 1 while c2pwrite is None. So fd 1 (errwrite) correctly gets duped to 2. But then, since errwrite is not None and it's not in (p2cread, c2pwrite, 2), the child closes fd 1.

The equivalent thing happens if you supply stdout=sys.stderr and the child attempts to write to its stderr.

I've attached a patch to fix this. It simply adds 2 and 2 to the list of fds not to close for c2pwrite and errwrite, respectively.

This patch is against the 2.6.5 release.

There is also a workaround, in case anyone else is affected by this bug before a fix has been released:

>>> import os, subprocess, sys
>>> subprocess.call(('echo', 'foo'), stderr=os.dup(sys.stdout.fileno()))
foo
0
>>> 

(There could be a similar bug relating to the child's stdin, but I haven't investigated that.)
History
Date User Action Args
2010-06-24 20:12:16krsetrecipients: + kr
2010-06-24 20:12:16krsetmessageid: <1277410336.39.0.223644435027.issue9074@psf.upfronthosting.co.za>
2010-06-24 20:12:14krlinkissue9074 messages
2010-06-24 20:12:14krcreate