How do I make a Python .bat executable file?

Andy Robinson andy at robanal.demon.co.uk
Mon Dec 27 16:09:46 EST 1999


Robert Shockley <vaton at postoffice.pacbell.net> wrote:

>What kind of 'wrapper' is needed to make a python script an executable
>.bat file in Windows? Is the she-bang (#!/...)  line required? I would
>appreciate any help. ~Rob~

Windows does not use the pound-bang trick nor the idea of executable
permissions.  Instead, it looks at file extensions of anything other
than CON, EXE and BAT and figures out what app to run them with.

On NT, by default the .py extension is associated with Python during
installation of Python, so you can execute 'myscript.py' directly from
a command prompt, or a double-click in an explorer window.

You may go a step further and edit the PATHEXT environment variable in
Control Panel / System / Environment  (type 'set' in a dos box to see
its current settings) and adding '.PY' to the list; then you can just
type 'myscript' to execute 'myscript.py'.

On 95/98, I tend to create one line batch files which call the python
script with 'python.exe myscript.py %1 %2 %3...' etc.

Regards,

Andy







More information about the Python-list mailing list