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


Eugene Lazutkin 5:11 PM on 27 May 2006

Raymond implemented something similar using straight Windows .bat:


Add a comment:

Ignore this:
not displayed and no spam.
Leave this empty:
not searched.
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.