Skip to content

Commit 1d85c2f

Browse files
committed
pythongh-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. Signed-off-by: Paulo Neves <[email protected]>
1 parent 0e15c31 commit 1d85c2f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Lib/subprocess.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,9 @@ def __init__(self, args, bufsize=-1, executable=None,
834834
if not isinstance(bufsize, int):
835835
raise TypeError("bufsize must be an integer")
836836

837+
if stdout is STDOUT:
838+
raise ValueError("STDOUT can only be used for stderr")
839+
837840
if pipesize is None:
838841
pipesize = -1 # Restore default
839842
if not isinstance(pipesize, int):

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)