This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Popen with shell=True yield mangled repr output
Type: behavior Stage: commit review
Components: Library (Lib) Versions: Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: WildCard65, gregory.p.smith, miss-islington, mkocher, rhettinger
Priority: normal Keywords: 3.9regression, patch

Created on 2021-04-08 18:42 by mkocher, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 25338 merged mkocher, 2021-04-10 23:58
PR 26510 merged gregory.p.smith, 2021-06-03 03:50
Messages (6)
msg390542 - (view) Author: (mkocher) * Date: 2021-04-08 18:42
When using Popen with shell=True, the output of the repr is not particularly user friendly. 

When using the form `p = Popen('python --version'.split())`, the output is reasonably output in a user friendly form of `<Popen: returncode: None args: ['python', '--version']>`. 

However, when running with `shell=True`, the output is mangled.

For example, trying to run `python --help` via `p = Popen('python --version', shell=True)` yields the following output.

`<Popen: returncode: None args: ['p', 'y', 't', 'h', 'o', 'n', ' ', '-', '-',...>`

The original change appears to be motivated by https://bugs.python.org/issue38724 

and the PR here:

https://github.com/python/cpython/pull/17151/files
msg390579 - (view) Author: William Pickard (WildCard65) * Date: 2021-04-09 01:44
Actually, the problem is independent of the value of "shell", the __repr__ function from the initial PR that introduced it expects "args" to be a sequence and converts it to a list.
msg391751 - (view) Author: (mkocher) * Date: 2021-04-24 01:29
There's a PR up with removed `list` call as well as improved test coverage for the case where args is passed into Popen as a string. 

Hopefully this can get merged before things starting getting crazy with the 3.10 release crunch.
msg391757 - (view) Author: (mkocher) * Date: 2021-04-24 04:37
There also appears to be an issue when args are provided as a `pathlib.Path` instance.


Python 3.9.2 | packaged by conda-forge | (default, Feb 21 2021, 05:02:20) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from subprocess import Popen

In [2]: from pathlib import Path

In [3]: p = Path('/usr/local/bin/gtrue')

In [4]: x = Popen(p)

In [5]: repr(x)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-5091dd558c19> in <module>
----> 1 repr(x)

~/opt/miniconda3/envs/core/lib/python3.9/subprocess.py in __repr__(self)
    990         obj_repr = (
    991             f"<{self.__class__.__name__}: "
--> 992             f"returncode: {self.returncode} args: {list(self.args)!r}>"
    993         )
    994         if len(obj_repr) > 80:

TypeError: 'PosixPath' object is not iterable
msg392171 - (view) Author: miss-islington (miss-islington) Date: 2021-04-28 08:16
New changeset db0c5b786df961785ae8c803f5572ae0c8dadcc7 by M. Kocher in branch 'master':
bpo-43776: Remove list call from args in Popen repr (GH-25338)
https://github.com/python/cpython/commit/db0c5b786df961785ae8c803f5572ae0c8dadcc7
msg394983 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2021-06-03 04:15
New changeset 5a8ddcc4524dca3880d7fc2818814ffae1cfb8a2 by Gregory P. Smith in branch '3.9':
[3.9] bpo-43776: Remove list call from args in Popen repr (GH-25338) (GH-26510)
https://github.com/python/cpython/commit/5a8ddcc4524dca3880d7fc2818814ffae1cfb8a2
History
Date User Action Args
2022-04-11 14:59:44adminsetgithub: 87942
2021-06-03 04:16:05gregory.p.smithsetstatus: open -> closed
resolution: fixed
stage: patch review -> commit review
2021-06-03 04:15:33gregory.p.smithsetmessages: + msg394983
2021-06-03 03:50:22gregory.p.smithsetpull_requests: + pull_request25106
2021-04-28 08:16:44miss-islingtonsetnosy: + miss-islington
messages: + msg392171
2021-04-28 07:59:22gregory.p.smithsetkeywords: + 3.9regression
2021-04-24 04:38:00mkochersetmessages: + msg391757
2021-04-24 01:29:33mkochersetmessages: + msg391751
2021-04-11 08:10:00rhettingersetnosy: + rhettinger
2021-04-11 05:47:36gregory.p.smithsetassignee: gregory.p.smith

nosy: + gregory.p.smith
versions: + Python 3.10
2021-04-10 23:58:13mkochersetkeywords: + patch
stage: patch review
pull_requests: + pull_request24073
2021-04-09 01:44:40WildCard65setnosy: + WildCard65
messages: + msg390579
2021-04-08 18:42:23mkochercreate