Creating a BAT file for python script


Question

How can I create a simple BAT file that will run my python script located at C:\somescript.py?

1
50
4/15/2019 10:20:24 PM

Accepted Answer

c:\python27\python.exe c:\somescript.py %*
60
12/31/2010 4:55:06 PM

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.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon