Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c7635892
Commit
c7635892
authored
May 13, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #22274: Redirect stderr=STDOUT when stdout not redirected, by Akira Li
parent
07451ddd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
1 deletion
+28
-1
Lib/subprocess.py
Lib/subprocess.py
+4
-1
Lib/test/test_subprocess.py
Lib/test/test_subprocess.py
+21
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/subprocess.py
View file @
c7635892
...
@@ -1401,7 +1401,10 @@ class Popen(object):
...
@@ -1401,7 +1401,10 @@ class Popen(object):
elif
stderr
==
PIPE
:
elif
stderr
==
PIPE
:
errread
,
errwrite
=
os
.
pipe
()
errread
,
errwrite
=
os
.
pipe
()
elif
stderr
==
STDOUT
:
elif
stderr
==
STDOUT
:
if
c2pwrite
!=
-
1
:
errwrite
=
c2pwrite
errwrite
=
c2pwrite
else
:
# child's stdout is not set, use parent's stdout
errwrite
=
sys
.
__stdout__
.
fileno
()
elif
stderr
==
DEVNULL
:
elif
stderr
==
DEVNULL
:
errwrite
=
self
.
_get_devnull
()
errwrite
=
self
.
_get_devnull
()
elif
isinstance
(
stderr
,
int
):
elif
isinstance
(
stderr
,
int
):
...
...
Lib/test/test_subprocess.py
View file @
c7635892
...
@@ -504,6 +504,27 @@ class ProcessTestCase(BaseTestCase):
...
@@ -504,6 +504,27 @@ class ProcessTestCase(BaseTestCase):
tf
.
seek
(
0
)
tf
.
seek
(
0
)
self
.
assertStderrEqual
(
tf
.
read
(),
b"strawberry"
)
self
.
assertStderrEqual
(
tf
.
read
(),
b"strawberry"
)
def
test_stderr_redirect_with_no_stdout_redirect
(
self
):
# test stderr=STDOUT while stdout=None (not set)
# - grandchild prints to stderr
# - child redirects grandchild's stderr to its stdout
# - the parent should get grandchild's stderr in child's stdout
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'import sys, subprocess;'
'rc = subprocess.call([sys.executable, "-c",'
' "import sys;"'
' "sys.stderr.write(
\
'
42
\
'
)"],'
' stderr=subprocess.STDOUT);'
'sys.exit(rc)'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
stdout
,
stderr
=
p
.
communicate
()
#NOTE: stdout should get stderr from grandchild
self
.
assertStderrEqual
(
stdout
,
b'42'
)
self
.
assertStderrEqual
(
stderr
,
b''
)
# should be empty
self
.
assertEqual
(
p
.
returncode
,
0
)
def
test_stdout_stderr_pipe
(
self
):
def
test_stdout_stderr_pipe
(
self
):
# capture stdout and stderr to the same pipe
# capture stdout and stderr to the same pipe
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
...
...
Misc/NEWS
View file @
c7635892
...
@@ -118,6 +118,9 @@ Core and Builtins
...
@@ -118,6 +118,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #22274: In the subprocess module, allow stderr to be redirected to
stdout even when stdout is not redirected. Patch by Akira Li.
- Issue #25745: Fixed leaking a userptr in curses panel destructor.
- Issue #25745: Fixed leaking a userptr in curses panel destructor.
- Issue #26977: Removed unnecessary, and ignored, call to sum of squares helper
- Issue #26977: Removed unnecessary, and ignored, call to sum of squares helper
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment