"Bootstrap" python script in the Windows shell without .py / .pyw associations

Posted by PabloG on Stack Overflow See other posts from Stack Overflow or by PabloG
Published on 2010-03-18T18:56:00Z Indexed on 2010/03/18 19:11 UTC
Read the original article Hit count: 623

Filed under:
|

Sometimes (in customer's PCs) I need a python script to execute in the Windows shell like a .CMD or .BAT, but without having the .py or .pyw extensions associated with PYTHON / PYTHONW.

I came out with a pair of 'quick'n dirty' solutions:

1)

"""
e:\devtool\python\python.exe %0 :: or %PYTHONPATH%\python.exe
goto eof:
""" 
# Python test
print "[works, but shows shell errors]"

2)

@echo off
for /f "skip=4 delims=xxx" %%l in (%0) do @echo %%l | e:\devtools\python\python.exe
goto :eof
::----------

# Python test
print "[works better, but is somewhat messy]"

Do you know a better solution? (ie: more concise or elegant)

© Stack Overflow or respective owner

Related posts about python

Related posts about shell