diff options
Diffstat (limited to 'Lib/shutil.py')
| -rw-r--r-- | Lib/shutil.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index 86c32fa..e4b640c 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -1077,10 +1077,13 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None): return (os.path.exists(fn) and os.access(fn, mode) and not os.path.isdir(fn)) - # Short circuit. If we're given a full path which matches the mode - # and it exists, we're done here. - if _access_check(cmd, mode): - return cmd + # If we're given a path with a directory part, look it up directly rather + # than referring to PATH directories. This includes checking relative to the + # current directory, e.g. ./script + if os.path.dirname(cmd): + if _access_check(cmd, mode): + return cmd + return None path = (path or os.environ.get("PATH", os.defpath)).split(os.pathsep) |
