[New-bugs-announce] [issue37894] [win] shutil.which can not find the path if 'cmd' include directory path and not include extension name

Wator Sead report at bugs.python.org
Tue Aug 20 11:59:37 EDT 2019


New submission from Wator Sead <seahoh at gmail.com>:

The current code is:
    ...
    if os.path.dirname(cmd):
        if _access_check(cmd, mode):
            return cmd
        return None
    ...

In Windows, if 'cmd' include directory path and not include extension name, it return 'None'.
e.g. a file's path is 'd:\dir\app.exe', call shutil.which with 'cmd=="d:\dir\app"'.

How about this patch:
    ...
    if os.path.dirname(cmd):
        path, cmd = os.path.split(cmd)
    ...

----------
components: Library (Lib)
messages: 350019
nosy: seahoh
priority: normal
severity: normal
status: open
title: [win] shutil.which can not find the path if 'cmd' include directory path and not include extension name
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8

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


More information about the New-bugs-announce mailing list