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.

classification
Title: subprocess(..., stdout=sys.stderr) closes stderr for child
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 2.7, Python 2.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Subprocess error if fds 0,1,2 are closed
View: 10806
Assigned To: Nosy List: Evgeny.Tarasov, alexey-smirnov, neologix, r.david.murray, socketpair, vstinner
Priority: normal Keywords: patch

Created on 2011-06-03 09:47 by socketpair, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
z.patch socketpair, 2011-06-03 10:05 patch for the problem
Messages (5)
msg137510 - (view) Author: Марк Коренберг (socketpair) * Date: 2011-06-03 09:47
How to test:
----------------
#! /usr/bin/python
import subprocess, sys

# will print err to sys.stderr
subprocess.call(['rmdir', '/no_such_dir'])

# will NOT print err to sys.stderr
subprocess.call(['rmdir', '/no_such_dir'], stdout=sys.stderr)
----------------

According to strace, in child process:
-----------------
dup2(2, 1) // that's what I expect, okay
close(2) // that's I was not expect, so bug here
execve(...)
-----------------

Bug is in subprocess.py:
(search for "dup2" in file)
I do not known how to fix correctly. Logick in this module is brain damaged in some places.

-----------------------------
# Dup fds for child
if p2cread is not None:
    os.dup2(p2cread, 0)
if c2pwrite is not None:
    os.dup2(c2pwrite, 1)
if errwrite is not None:
    os.dup2(errwrite, 2)

# Close pipe fds.  Make sure we don't close the same
# fd more than once, or standard fds.
if p2cread is not None and p2cread not in (0,):
    os.close(p2cread)
if c2pwrite is not None and c2pwrite not in (p2cread, 1):
    os.close(c2pwrite)
if errwrite is not None and errwrite not in (p2cread, c2pwrite, 2):
    os.close(errwrite)
-------------------------
msg137512 - (view) Author: Марк Коренберг (socketpair) * Date: 2011-06-03 10:05
patch (was not tested) attached
msg137517 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2011-06-03 11:55
It's a duplicate of issue #10806, fixed in 2.7, 3.1 and 3.2.
Closing.
msg137518 - (view) Author: Марк Коренберг (socketpair) * Date: 2011-06-03 13:23
Why not to backport to python 2.6 ? this is the bug, not a feature.
msg137519 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-06-03 14:27
Because 2.6 is in security-fix-only mode.
History
Date User Action Args
2022-04-11 14:57:18adminsetgithub: 56460
2011-06-03 14:27:30r.david.murraysetnosy: + r.david.murray
messages: + msg137519
2011-06-03 13:23:52socketpairsetmessages: + msg137518
2011-06-03 11:55:07neologixsetstatus: open -> closed

superseder: Subprocess error if fds 0,1,2 are closed

nosy: + neologix
messages: + msg137517
resolution: duplicate
stage: resolved
2011-06-03 10:42:14vstinnersetnosy: + vstinner
2011-06-03 10:26:57Evgeny.Tarasovsetnosy: + Evgeny.Tarasov
2011-06-03 10:05:38socketpairsetfiles: + z.patch
keywords: + patch
messages: + msg137512
2011-06-03 09:48:18alexey-smirnovsetnosy: + alexey-smirnov
2011-06-03 09:47:08socketpaircreate