RunPy (was py2bat (was: How do I make a Python .bat executable file?))

Alex Martelli alex at magenta.com
Sat Jan 8 08:55:57 EST 2000


Piet van Oostrum writes:

> For perl there is a runperl.exe which, if copied to myscript.exe and run,
> calls perl myscript.pl with all arguments passed unchanged. It would
> probably be simple to clone this for python. I have never seen the source,
> however, and I am too lazy to write it myself.

Haven't seen the program you mention, either, but I've had a go
at writing a version for Python, just in case some should find it
useful.  http://aleax.supereva.it/Python/runpy.zip (2477 bytes)
has both the source (a single runpy.cpp file, to be compiled as a
console application) and the executable (runpy.exe, which is
compiled and linked to use the MSVCRT.DLL version of runtime).

This runpy.exe should do exactly what you mention; renamed to
foobar.exe, it looks for foobar.py along the PATH and, if found,
runs python.exe on it (assuming _that_ is along the PATH, too!)
with the same, unchanged arguments.

If anybody does download and try it, I'd be grateful for any
feedback, of course.

One can, of course, easily think of a few useful variations: e.g.,
a version that is a window app rather than a console one (and
which runs pythonw rather than python), options to look for
the script elsewhere than on the PATH (e.g., in the same
directory as the renamed runpy.exe itself, or on PYTHONPATH),
ways to pass option-flags to python.exe.  I'm quite willing to
entertain any such suggestions if anybody has any use for
them -- it's all really very simple (the current runpy.cpp is
77 lines including error diagnosis and reporting, for example).


Alex






More information about the Python-list mailing list