Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29582 > unrolled thread

Re: portable way of locating an executable (like which)

Started byGelonida N <gelonida@gmail.com>
First post2012-09-21 01:07 +0200
Last post2012-09-21 01:07 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: portable way of locating an executable (like which) Gelonida N <gelonida@gmail.com> - 2012-09-21 01:07 +0200

#29582 — Re: portable way of locating an executable (like which)

FromGelonida N <gelonida@gmail.com>
Date2012-09-21 01:07 +0200
SubjectRe: portable way of locating an executable (like which)
Message-ID<mailman.980.1348182445.27098.python-list@python.org>
On 09/21/2012 12:21 AM, Chris Angelico wrote:
> On Fri, Sep 21, 2012 at 7:47 AM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
>> On 20/09/2012 22:06, 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.
>>>
>>> Did anybody already implement such a function.
>>
>> Searching found nothing obvious to me :(

I was afraid so, but wanted to be sure
>>
>>> If not, is there a portable way of splitting the environment variable
>>> PATH?
>> With os.sep ?
>
> os.sep is the directory separator, but os.pathsep may be what you
> want.

Thanks,
os.pathsep was the missing piece for portably splitting the searchpath

>  Between that and os.getenv('path') you can at least get the
> directories. Then on Windows, you also need to check out
> os.getenv('pathext') and split _that_ on the semicolon, and try each
> of those as a file extension. I'm not sure whether or not Windows will
> add extensions from pathext if one is given on the command line - for
> instance, if typing "foo.exe" will search for "foo.exe.bat" - but the
> basics are there.
>
For what I am doing I can even skip trying the pathexts, the ext is 
already given, but good to know :-)


> Alternatively, there may be a Win32 API funct5ion that does this.
> Would be worth a look.

Yeah true, but ideally I'd like to avoid platform detection and
just have a generic function.



[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web