portable way of locating an executable (like which)

Tarek Ziadé tarek at ziade.org
Fri Sep 21 04:12:29 EDT 2012


On 9/21/12 1:59 AM, Nobody wrote:
> On Thu, 20 Sep 2012 23:06:46 +0200, Gelonida N wrote:
>
>> I'd like to implement the equivalent functionality of the unix command
>> /usr/bin/which
>>
>> The function should work under Linux and under windows.
> Note that "which" attempts to emulate the behaviour of execvp() etc. The
> exec(3) manpage will explain the precise algorithm used (e.g. they skip
> files for which the process lacks execute permission).
>
> Also, note that the shell has built-in commands, functions, and aliases in
> addition to programs. The "type" built-in command performs a similar
> function to "which" but using the shell's semantics. On some systems,
> the default configuration may alias "which" to "type".
>
> On Windows, there's a host of different "execute program" interface, all
> with subtly different semantics: which extensions they will run, which
> extensions can be omitted, which paths are used (e.g. %PATH%, paths
> from the registry, current directory).
>
You can also look at shutil.which

http://hg.python.org/cpython/file/aa153b827d17/Lib/shutil.py#l974


Mmmm I wonder why it's removed in the last revs..



More information about the Python-list mailing list