python / python/cpython

Windows: Provide an option to disable search in CWD on `shutil.which`

Open
#91,558 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

OS-windows
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

I would like to search for an executable in the PATH but not from the current working directory (cwd). By default, as documented in shutil.which, it prepends the cwd before PATH, so it's not possible to get the expected executable.

For example, I have a whoami.exe in the cwd but I would like to get the one from the system32 directory; there's no way to do so using shutil.which.

>>> import shutil
>>> shutil.which('whoami')
'.\\whoami.EXE'

I think it makes sense for that to be the default behaviour since that's how it is on Windows. I would like to have a parameter to disable this behaviour in shutil.which.

Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the shutil.which entry point and its documentation, focusing on the Windows-specific current-directory search described in the issue. Done means callers can opt out of that search and find the matching executable later in PATH, including the whoami.exe example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.