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: subprocess.run on windows does not convert path to string
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Can't pass Path like objects to subprocess api's on Windows.
View: 41649
Assigned To: Nosy List: eric.smith, eryksun, kaushik.ghose, paul.moore, steve.dower, terry.reedy, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2020-09-09 17:54 by kaushik.ghose, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg376651 - (view) Author: Kaushik G (kaushik.ghose) Date: 2020-09-09 17:54
a call of the form `subprocess.run([x, y, z])` where one of the elements is a `pathlib.Pat`h fails on windows because the path is not converted to a string as it should. This works fine (as expected) on macOS and Linux.

A typical error message is:

`TypeError: argument of type 'WindowsPath' is not iterable`
msg376653 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-09-09 18:07
Among others, see:
issue 41649
issue 31961

In general, I think the consensus is that the caller should convert each argument to a string. It's not subprocess's job to convert each parameter to a string.
msg376654 - (view) Author: Kaushik G (kaushik.ghose) Date: 2020-09-09 18:12
Thank you for your response.

There are two concerns I have here.

1. Python's promise of being straightforward. In MOST cases pathlib.Path objects do the right thing, casting to a string such that pathlib.Path is a drop in replacement. This exception is unexpected.

2. Cross platform consistency. Looks like this works on macOS and Linux. Why should it fail on Windows?

Thanks!
msg376657 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2020-09-09 19:05
The underlying subprocess.Popen class was updated in 3.8 to support path-like objects in `args` (with shell=False) and `executable` on Windows [1]. This change was not backported to 3.6 and 3.7.

---

[1] https://docs.python.org/3/library/subprocess.html#subprocess.Popen
msg376759 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-09-12 01:25
Also, 3.7 only get security patches.
History
Date User Action Args
2022-04-11 14:59:35adminsetgithub: 85919
2020-09-12 01:25:43terry.reedysetnosy: + terry.reedy
messages: + msg376759
2020-09-12 01:25:10terry.reedysetstatus: open -> closed
superseder: Can't pass Path like objects to subprocess api's on Windows.
resolution: duplicate
stage: resolved
2020-09-09 19:05:06eryksunsetnosy: + eryksun
messages: + msg376657
2020-09-09 18:12:26kaushik.ghosesetmessages: + msg376654
2020-09-09 18:07:45eric.smithsetnosy: + eric.smith
messages: + msg376653
2020-09-09 17:54:01kaushik.ghosecreate