your_script.bat:
set VAR_1=this
set VAR_2=that
python your_script.py %1 %VAR_1% %VAR_2%
Answer from Tim Henigan on Stack Overflowyour_script.bat:
set VAR_1=this
set VAR_2=that
python your_script.py %1 %VAR_1% %VAR_2%
Another option is to write arguments right after the python script, following the example:
python your_script.py this that
If you are using Linux .sh file, remember to run dos2unix XXX.sh before you run:
bash XXX.sh.
The reason, in a simple version, is that dos and unix use different newline breakers.
Creating a BAT file for python script - Stack Overflow
windows - Running a batch file with parameters in Python OR F# - Stack Overflow
Executing Python Script from Bat File
path passed as argument from Batch file is a 'list', not a string
Videos
c:\python27\python.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.
Python is similar.
import os
os.system("run-client.bat param1 param2")
If you need asynchronous behavior or redirected standard streams.
from subprocess import *
p = Popen(['run-client.bat', param1, param2], stdout=PIPE, stderr=PIPE)
output, errors = p.communicate()
p.wait() # wait for process to terminate
In F#, you could use the Process class from the System.Diagnostics namespace. The simplest way to run the command should be this:
open System.Diagnostics
Process.Start("run-client.bat", "param1 param2")
However, if you need to provide more parameters, you may need to create ProcessStartInfo object first (it allows you to specify more options).
Hi everyone,
Really struggling with this. I'm trying to execute a python script by just double clicking a .bat file. The problem is I need some libraries from my Anaconda environment, so I need to activate my environment first ( C:\soft\athenes )
%windir%\System32\cmd.exe "/K" C:\soft\Anaconda3\Scripts\activate.bat C:\soft\athenes && python "C:\Work\Python\Administrative\my_script.py" pause
I've managed to activate my anaconda environment but it's not executing the script.
Thanks for your help !