summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/subprocess.py3
-rw-r--r--Lib/test/test_subprocess.py7
-rw-r--r--Misc/NEWS.d/next/Library/2024-03-26-11-48-39.gh-issue-98966.SayV9y.rst2
3 files changed, 12 insertions, 0 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index dbe1527..d7c7b45 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -839,6 +839,9 @@ class Popen:
if not isinstance(bufsize, int):
raise TypeError("bufsize must be an integer")
+ if stdout is STDOUT:
+ raise ValueError("STDOUT can only be used for stderr")
+
if pipesize is None:
pipesize = -1 # Restore default
if not isinstance(pipesize, int):
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 70452ca..9ecd842 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1763,6 +1763,13 @@ class RunFuncTestCase(BaseTestCase):
self.assertIn(b'BDFL', cp.stdout)
self.assertIn(b'FLUFL', cp.stderr)
+ def test_stdout_stdout(self):
+ # run() refuses to accept stdout=STDOUT
+ with self.assertRaises(ValueError,
+ msg=("STDOUT can only be used for stderr")):
+ self.run_python("print('will not be run')",
+ stdout=subprocess.STDOUT)
+
def test_stdout_with_capture_output_arg(self):
# run() refuses to accept 'stdout' with 'capture_output'
tf = tempfile.TemporaryFile()
diff --git a/Misc/NEWS.d/next/Library/2024-03-26-11-48-39.gh-issue-98966.SayV9y.rst b/Misc/NEWS.d/next/Library/2024-03-26-11-48-39.gh-issue-98966.SayV9y.rst
new file mode 100644
index 0000000..e819a1e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-03-26-11-48-39.gh-issue-98966.SayV9y.rst
@@ -0,0 +1,2 @@
+In :mod:`subprocess`, raise a more informative message when
+``stdout=STDOUT``.