wh.py

I like the ‘which’ command on Unix; it finds the executable on the path that will be executed when you type any given command. I have cygwin, which provides a which.exe, but I don’t like the way it Unix-izes all the paths, and it doesn’t understand the way Windows actually finds executables. Visual Studio provides a where.exe, which does the same sort of thing, but it requires the full file name (foo.exe) rather than just the command (foo). If I knew it was a .exe rather than a .cmd, I probably wouldn’t need help in the first place!

I wrote wh.py to do the job right: it understands the full semantics of mapping Windows commands onto files in the file system (including the PATH and PATHEXT environment variables), and it has the extra bonus of listing all of the files that qualify, in search order, so you can see that files are being occluded by each other.

There are command-line switches to control where the path and extension list are read from, or you can provide explicit lists for these. Also, the current directory is read before the path in the default case, to better match the way Windows actually works.

Download: wh.py

Comments

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.