How do I find executable files from the environment PATH variable?

Matt Gerrans matt_gerrans at
Thu Aug 8 00:24:56 CEST 2002

On Windows, the PATH + PATHEXT environment variables plus registered
associations and file types all play a part in what is an "executable."
The in the tools\scripts directory just checks os.stat(), so it
misses a lot of things.   I wrote a simple that shows all the
possible culprits in the path (in the order in which they are found in the
current directory, then the path, of course), like so:

D:\>which which

(as you can see, I've also setup things so that Python files can be run as
if they are executables (even without the .py -- that is what PATHEXT

This is, of course, all platform-dependent, but I don't think this stuff can
be handled in a very platform-universal way (without the LCD effect), so a
platform check would be required.

- Matt

More information about the Python-list mailing list