[issue15533] subprocess.Popen(cwd) documentation: Posix vs Windows

ban report at bugs.python.org
Thu Aug 12 11:10:31 EDT 2021


ban <cwendling at hypra.fr> added the comment:

>> "In particular, the function looks for executable (or for the 
>> first item in args) relative to cwd if the executable path is 
>> a relative path." 
>
> For POSIX, this should be stated as a "relative path without a slash in
> it" or a "relative path without a directory in it". An unqualified
> filename is a relative path that won't be resolved against `cwd`,
> unless there's a "." entry in PATH.

While I don't understand the wording proposed (that seem backwards to me?), I do think it would be important to fix this.

I just got puzzled and spent some effort writing a workaround *not to look in cwd* for a bare command name, before I got so skeptical I actually tried empirically what Python would do -- and see the behavior was sensible and `cwd` was taken into account *only if the executable had a path component in it*.

Any other behavior is annoying IMO as it means using a `cwd` *requires* one to pass in an absolute path to the executable not to risk running an unexpected executable, which basically makes support for looking up executable in the system PATH unusable if using a `cwd`.
It would also be somewhat inconsistent with the idea that `cwd` only *changes* the current directory prior to execution, as it would suggest the behavior is not the same when using `cwd=None` and `cwd=os.getcwd()`.

So I'd suggest amending the wording in some way, maybe something like
"In particular, the function looks for executable (or for the first item in args) relative to cwd if the executable has an explicit relative path."
or something like that, possibly even dropping in an example.
The problem with the current wording is that usually an unqualified name *is* a relative path, whereas here one should somehow understand that it means "if it has a path component and that path component is relative", or the more down-to-earthy "if the executable starts with './' or '../'".

----------
nosy: +ban

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


More information about the Python-bugs-list mailing list