[issue41649] Can't pass Path like objects to subprocess api's on Windows.

2020-08-27 Thread Jani Mikkonen


New submission from Jani Mikkonen :

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.

--
components: Windows
messages: 375993
nosy: paul.moore, rasjani, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Can't pass  Path like objects to subprocess api's on Windows.
type: behavior
versions: Python 3.10, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

___
Python tracker 
<https://bugs.python.org/issue41649>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41649] Can't pass Path like objects to subprocess api's on Windows.

2020-08-28 Thread Jani Mikkonen


Jani Mikkonen  added the comment:

@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 ..

--

___
Python tracker 
<https://bugs.python.org/issue41649>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com