Skip to content

Commit b7d2917

Browse files
committed
gh-98966: Handle stdout=subprocess.STDOUT
Explicitly handle the case where stdout=STDOUT as otherwise the existing error handling gets confused and reports hard to understand errors.
1 parent 0e15c31 commit b7d2917

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Lib/subprocess.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,8 @@ def __init__(self, args, bufsize=-1, executable=None,
854854
if creationflags != 0:
855855
raise ValueError("creationflags is only supported on Windows "
856856
"platforms")
857+
if stdout is STDOUT:
858+
raise ValueError("STDOUT can only be used for stderr")
857859

858860
self.args = args
859861
self.stdin = None

Lib/test/test_subprocess.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,13 @@ def test_capture_output(self):
16951695
self.assertIn(b'BDFL', cp.stdout)
16961696
self.assertIn(b'FLUFL', cp.stderr)
16971697

1698+
def test_stdout_stdout(self):
1699+
# run() refuses to accetp stdout=STDOUT
1700+
with self.assertRaises(ValueError,
1701+
msg=("STDOUT can only be used for stderr")) as c:
1702+
output = self.run_python("print('will not be run')",
1703+
stdout=subprocess.STDOUT)
1704+
16981705
def test_stdout_with_capture_output_arg(self):
16991706
# run() refuses to accept 'stdout' with 'capture_output'
17001707
tf = tempfile.TemporaryFile()

0 commit comments

Comments
 (0)