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


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

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

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2012-09-20 16:32 -0600
Last post2012-09-20 16:32 -0600
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) Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-20 16:32 -0600

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

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-09-20 16:32 -0600
SubjectRe: portable way of locating an executable (like which)
Message-ID<mailman.978.1348180394.27098.python-list@python.org>
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]

[toc] | [standalone]


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


csiph-web