[New-bugs-announce] [issue45048] subprocess.run(capture_output=Bool) does the opposite of expected

DragonEggBedrockBreaking report at bugs.python.org
Sun Aug 29 17:12:54 EDT 2021


New submission from DragonEggBedrockBreaking <cuber3million at gmail.com>:

If you run subprocess.run(capture_output=True), it doesn't show output, but if you run subprocess.run(capture_output=False) (or if you just run subprocess.run() since False is default), it does show output. In the example in the docs, it shows this in the examples section:

```py
>>> subprocess.run(["ls", "-l"])  # doesn't capture output
CompletedProcess(args=['ls', '-l'], returncode=0)

>>> subprocess.run(["ls", "-l", "/dev/null"], capture_output=True)
CompletedProcess(args=['ls', '-l', '/dev/null'], returncode=0,
stdout=b'crw-rw-rw- 1 root root 1, 3 Jan 23 16:23 /dev/null\n', stderr=b'')
```

This clearly shows capture_output showing output if true but not if false. Test code:

```py
import subprocess
subprocess.run("dir", shell=True, capture_output=False)
subprocess.run("dir", shell=True, capture_output=False)
```

Other notes: for some reason I get an error if I don't add shell=True, so maybe that contributes? I am on Windows 10 if that matters.

----------
components: Library (Lib)
messages: 400561
nosy: DragonEggBedrockBreaking
priority: normal
severity: normal
status: open
title: subprocess.run(capture_output=Bool) does the opposite of expected
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45048>
_______________________________________


More information about the New-bugs-announce mailing list