Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't pass Path like objects to subprocess api's on Windows. #85815

Open
rasjani mannequin opened this issue Aug 27, 2020 · 5 comments
Open

Can't pass Path like objects to subprocess api's on Windows. #85815

rasjani mannequin opened this issue Aug 27, 2020 · 5 comments
Labels
3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes OS-windows topic-subprocess Subprocess issues. type-bug An unexpected behavior, bug, or error

Comments

@rasjani
Copy link
Mannequin

rasjani mannequin commented Aug 27, 2020

BPO 41649
Nosy @terryjreedy, @pfmoore, @tjguk, @zware, @serhiy-storchaka, @zooba, @tirkarthi, @rasjani

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-08-27.14:25:18.967>
labels = ['3.10', 'type-bug', '3.8', '3.9', 'OS-windows']
title = "Can't pass  Path like objects to subprocess api's on Windows."
updated_at = <Date 2020-09-12.01:28:59.018>
user = 'https://github.com/rasjani'

bugs.python.org fields:

activity = <Date 2020-09-12.01:28:59.018>
actor = 'terry.reedy'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Windows']
creation = <Date 2020-08-27.14:25:18.967>
creator = 'rasjani'
dependencies = []
files = []
hgrepos = []
issue_num = 41649
keywords = []
message_count = 5.0
messages = ['375993', '375995', '376024', '376043', '376760']
nosy_count = 8.0
nosy_names = ['terry.reedy', 'paul.moore', 'tim.golden', 'zach.ware', 'serhiy.storchaka', 'steve.dower', 'xtreak', 'rasjani']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue41649'
versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

@rasjani
Copy link
Mannequin Author

rasjani mannequin commented Aug 27, 2020

Following code:

from pathlib import Path
import os
import subprocess

dir_name = os.environ.get("WORKSPACE", None) or "."
output_directory = Path(dir_name) / "results"
res = subprocess.run(["mytest", "--output", output_directory])

Works on macos and linux but on windows, this causes "TypeError: argument of type 'WindowsPath' is not iterable" at https://github.com/python/cpython/blob/master/Lib/subprocess.py#L568

(line is different, depending on the actual python release but i guess that gives the idea where it is)..

Quick test to check if i can do " " in Path("/tmp") on posix platforms shows the same exception but with PosixPath type but apparently this sort of check does not happen on those platforms as the example code works fine there.

It would be nice to be able to pass path objects to subprocess api calls also in windows without explicitly casting the object into string before passing it as argument.

@rasjani rasjani mannequin added 3.7 (EOL) end of life 3.10 only security fixes 3.8 (EOL) end of life 3.9 only security fixes OS-windows type-bug An unexpected behavior, bug, or error labels Aug 27, 2020
@tirkarthi
Copy link
Member

See also https://bugs.python.org/issue31961

@rasjani
Copy link
Mannequin Author

rasjani mannequin commented Aug 28, 2020

@XTreak

I went thru the comments of the report you linked. It definitely looks like the discussion was related but it didnt really fix the issue here.

https://bugs.python.org/issue31961#msg311775 without trying out, that comment actually touches the underlying issue, on windows, list2cmdline throws that typeerror because iterated argument list (output_directory in my example) is WindowsPath and thus not iterable and and testing the arg with "in" operator fails ..

@serhiy-storchaka
Copy link
Member

I do not understand how you get this result. At that line of code arg can only be string, because it is a result of os.fsdecode(). Are you sure that you use Python version which includes bpo-31961 changes? What exactly Python version do you use?

@terryjreedy
Copy link
Member

I closed bpo-41753 as a duplicate of this.

On that issue, Eryk Sun said "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."

The latter is because 3.6 and 3.7 only get security patches. Jani, please verify that this is still an issue with 3.8 and/or 3.9.

@terryjreedy terryjreedy removed 3.7 (EOL) end of life labels Sep 12, 2020
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
atugushev pushed a commit to jazzband/pip-tools that referenced this issue Nov 3, 2022
For Windows support, this includes workarounds for
python/cpython#85815.
dand-oss pushed a commit to dand-oss/pip-tools that referenced this issue Nov 12, 2022
For Windows support, this includes workarounds for
python/cpython#85815.
@vstinner vstinner added the topic-subprocess Subprocess issues. label Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes OS-windows topic-subprocess Subprocess issues. type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants