Creating a BAT file for python script

Creating a BAT file for python script

c:python27python.exe c:somescript.py %*

Open a command line (⊞ Win+R, cmd, ↵ Enter)
and type python -V, ↵ Enter.

You should get a response back, something like Python 2.7.1.

If you do not, you may not have Python installed. Fix this first.

Once you have Python, your batch file should look like

@echo off
python c:somescript.py %*
pause

This will keep the command window open after the script finishes, so you can see any errors or messages. Once you are happy with it you can remove the pause line and the command window will close automatically when finished.

Creating a BAT file for python script

Heres how you can put both batch code and the python one in single file:

0<0# : ^
 
@echo off
echo batch code
python %~f0 %*
exit /b 0


print(python code)

the respectively starts and ends python multi line comments.

0<0# : ^ is more interesting – due to redirection priority in batch it will be interpreted like :0<0# ^ by the batch script which is a label which execution will be not displayed on the screen. The caret at the end will escape the new line and second line will be attached to the first line.For python it will be 0<0 statement and a start of inline comment.

The credit goes to siberia-man

Leave a Reply

Your email address will not be published.