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


Groups > comp.lang.python > #29580

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

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'though:': 0.07; 'extension.': 0.09; 'sep': 0.09; 'windows,': 0.09; 'extension': 0.13; 'extensions': 0.13; 'copied.': 0.16; 'echo': 0.16; 'separator,': 0.16; 'subject:which': 0.16; 'yup,': 0.16; 'wrote:': 0.17; 'instance,': 0.17; 'thu,': 0.17; 'tries': 0.17; 'typing': 0.17; 'windows': 0.19; 'split': 0.23; 'command': 0.24; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'looks': 0.26; 'first,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'there.': 0.28; 'chris': 0.28; 'subject:like': 0.29; "i'm": 0.29; 'file': 0.32; 'to:addr:python- list': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'add': 0.36; 'but': 0.36; 'subject: (': 0.36; 'enough': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'easy': 0.60; 'between': 0.63; '20,': 0.65; 'hello!': 0.65; 'to:name:python': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=vBL0r1TQQ5tFlJ2M3TSR9sWW9MphZILh8+mP3/7YdXM=; b=PsRZkX4Yi4fLFUkHf3tO5tT5GSDPJoJzBCrUnj2eJuvy8J7StozazX64skEW1XK47N mDqSwVl4VjtYTrrDMUvJUp8qT6y+dBIHIdXhb7BiWoSP4Y91Ty4qPkGEa2yAIezp0XBp TFuhvG01Jcxi78aYiMBPmCZu8AmaVojB6oc2taUxuqnuMSXJYVnNPMDWVV8PFEGp/HUg 8l9x6pvqi5kerAKR4vwq7MfgwLj41otkZjprF417dkruYPifaj+7kqCj0bph3J/rXJKo u6c3uj9RVCrvHWFSnyZUc2SfHjEnPFrjJf7sjLBnGamfiGOvi7zowKG0y1tJ40joyjmh zfyQ==
MIME-Version 1.0
In-Reply-To <CAPTjJmqDa8OxgnvPqK7X-OQk=4+DNuA8=-z5wAd8Nc_kKNvkRw@mail.gmail.com>
References <k3g0h6$mtr$1@ger.gmane.org> <k3g2t5$ar2$1@ger.gmane.org> <CAPTjJmqDa8OxgnvPqK7X-OQk=4+DNuA8=-z5wAd8Nc_kKNvkRw@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Thu, 20 Sep 2012 16:32:42 -0600
Subject Re: portable way of locating an executable (like which)
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.978.1348180394.27098.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1348180394 news.xs4all.nl 6978 [2001:888:2000:d::a6]:48314
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:29580

Show key headers only | View raw


On Thu, Sep 20, 2012 at 4:21 PM, Chris Angelico <rosuav@gmail.com> wrote:
> os.sep is the directory separator, but os.pathsep may be what you
> want. 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.

Easy enough to test:

C:\>echo echo hello! > foo.exe.bat

C:\>foo.exe
hello!

Yup, it does.  It looks like it tries it without the extension first, though:

C:\>copy c:\windows\notepad.exe foo.exe
        1 file(s) copied.

C:\>foo.exe
[starts notepad]

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: portable way of locating an executable (like which) Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-20 16:32 -0600

csiph-web