How do I find executable files from the environment PATH variable?
Matt Gerrans
matt_gerrans at hp.com
Wed Aug 7 18:24:56 EDT 2002
On Windows, the PATH + PATHEXT environment variables plus registered
associations and file types all play a part in what is an "executable."
The which.py in the tools\scripts directory just checks os.stat(), so it
misses a lot of things. I wrote a simple which.py 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
e:\code\python\which.py
d:\tools\WHICH.EXE
(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
does)).
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