[New-bugs-announce] [issue39692] Subprocess using list vs string

Niklas Smedemark-Margulies report at bugs.python.org
Wed Feb 19 19:11:43 EST 2020


New submission from Niklas Smedemark-Margulies <niklas.sm at gmail.com>:

Most (all?) of the functions in subprocess (run, Popen, etc) are supposed to accept either list or string, but the behavior when passing a list differs (and appears to be wrong).

For example, see below - invoking the command "exit 1" should give a return code of 1, but when using a list, the return code is 0.


```
>>> import subprocess


>>> # Example using run
>>> res1 = subprocess.run('exit 1', shell=True)
>>> res1.returncode
1
>>> res2 = subprocess.run('exit 1'.split(), shell=True)
>>> res2.returncode
0


>>> # Example using Popen
>>> p1 = subprocess.Popen('exit 1', shell=True)
>>> p1.communicate()
(None, None)
>>> p1.returncode
1
>>> p2 = subprocess.Popen('exit 1'.split(), shell=True)
>>> p2.communicate()
(None, None)
>>> p2.returncode
0
```

----------
messages: 362294
nosy: nik-sm
priority: normal
severity: normal
status: open
title: Subprocess using list vs string
type: behavior
versions: Python 3.7, Python 3.8

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


More information about the New-bugs-announce mailing list