Win32 : Making script.py executable in DOS box - PythonLauncher.exe (0/1)

Mikael Lyngvig mikael.lyngvig at toolwood.dk
Sun Jul 23 21:11:22 EDT 2000


On Sun, 02 Jul 2000 05:20:56 GMT, Neo Brave <neo_brave at my-deja.com>
wrote:

>I'm currently running Python scripts at the command line
>using C:\python\python script.py. Is there a way of making
>the MS-DOS box recognise the Python script as an executable
>file so I can just use the name "script.py"?

Please find attached a small executable program, PythonLauncher.exe,
which can be used to start Python programs under Win9x (and Windows
NT/2000).  This is an alternative to the batch files shown by others.

PythonLauncher.exe is a small program, which attempts to locate a
Python script named similarly to itself, then locate a Python
interpreter, and finally invoke the Python interpreter with the Python
script, and any parameters to the .exe itself, as parameters.

For instance, if you copy PythonLauncher.exe to foo.exe and run it
using "foo bar", it will attempt to locate foo.py, foo.pyc, or
foo.pyo.  If that succeeds, it will attempt to locate python.exe,
cgipython.exe, or pythonw.exe.  If that succeeds, it will invoke the
found Python interpreter with the parameters "fullpath\foo.py bar"
(where fullpath is replaced by the full path of the foo.py script).

The Python script and interpreter are searched in the following
locations:

1. The home directory of the PythonLauncher executable (the home
directory of foo.exe).

2. The directory defined by PYTHONHOME, if such an environment
variable exists.

3. The directories defined in the PATH environment variable.

Unlike batch files, PythonLauncher should work fine with redirection,
etc. (although I haven't tested this).

I've tried to reduce the size of the executable to as little as
possible, but I still end up with a 13 KB file.  That's a bit hefty,
but rarely a big problem in most systems.

If there's any interest in this utility I'll be happy to put up a web
page with it and write some proper documentation.  In that case,
please email me directly at mailto:mikael.lyngvig at toolwood.dk, since I
rarely have the time to follow this newsgroup.


-- Mikael




More information about the Python-list mailing list