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 Overflow
🌐
Python.org
discuss.python.org › python help
How to run batch file by using python code? - Python Help - Discussions on Python.org
July 7, 2022 - I am not getting any out put while run the batch file. If any one have idea about batch file code?
Discussions

Creating a BAT file for python script - Stack Overflow
How can I create a simple BAT file that will run my python script located at C:\somescript.py? More on stackoverflow.com
🌐 stackoverflow.com
windows - Running a batch file with parameters in Python OR F# - Stack Overflow
I searched the site, but I didn't see anything quite matching what I was looking for. I created a stand-alone application that uses a web service I created. To run the client I use: C:/scriptsdire... More on stackoverflow.com
🌐 stackoverflow.com
Executing Python Script from Bat File
Hi, I had a similar problem. You don’t need to necessarily activate the Anaconda environment. In my case, there were some paths missing in the environment variables. I’ll check here and let you know. More on reddit.com
🌐 r/learnpython
6
1
November 27, 2020
path passed as argument from Batch file is a 'list', not a string
sys.argv is a list of the arguments passed to the script. The 0th value in sys.argv is always the name / path of the script and it is added automatically. The 1st value and onwards are the values you passed to the script. In python '\' is used to escape characters which is how you write newlines and such, but if you want to use an actual '\' you need to escape it so you write '\\'. So to the program '\\' is a single backslash. try: path = sys.argv[1] More on reddit.com
🌐 r/learnpython
13
2
March 4, 2024
🌐
Quora
quora.com › How-do-I-pass-arguments-from-batch-file-as-a-function-to-python
How to pass arguments from batch file as a function to python - Quora
Answer (1 of 3): You can read arguments passed to a batch file like this [code]set arg1 = %1 set arg2 = %2 REM and so on... set arg9 = %9 REM if there are more arguments you can use SHIFT shift set arg10 = %9 shift set arg11 = %9 shift set arg12 = %9 REM and so on... [/code]You can also use [co...
🌐
Data to Fish
datatofish.com › batch-python-script
How to Create a Batch File to Run a Python Script
In this tutorial, you will create a batch file that runs a Python script when opened. ... To find the path of your Python, search python, right click on the relevant search result and click Open file location: In the Windows Explorer right click on the Python icon and click on Properties: ... Let's we have a Python script located inside folder named Test on your desktop. It's path looks something like this: ... Don't forget to use your paths and save the file with a .bat extension, e.g., script.bat.
🌐
Rupesh Bhandari
rupeshbhandari.com.np › posts › creating-a-batch-file-to-run-a-python-script-advanced-scenarios.md
Creating a Batch File to Run a Python Script: Advanced Scenarios | Rupesh Bhandari
February 11, 2025 - In the Python script, you can capture these arguments using sys.argv: ... If you need to run several Python scripts one after the other, you can chain the commands in the .bat file. In this scenario, the batch file will run the Python scripts sequentially, and the command prompt will display the output of each script. To avoid opening the command window or to run the script in the background, you can use the start command with /B.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-embed-python-code-in-batch-script
How To Embed Python Code In Batch Script - GeeksforGeeks
July 23, 2025 - The python_args.py file will contain the python print statement. which will require an argument during the execution of that file. This can be done using Python sys module. ... This batch script passes all arguments provided to the batch file ...
Find elsewhere
🌐
Humboldt
gis.humboldt.edu › OLM › old › Temp › 08_3_1_RunningPythonFromTheCommandLine.html
GIS Programming With Python - Running Scripts from the Command Line
Enter the following into Wing and save it as a file. ... Now enter "python <full path to the script>" into the command line and hit return. You'll see that the path to the script comes into the script as the first element in a list. Now try "python <full path to the script> test" and you'll ...
🌐
YouTube
youtube.com › pygpt
batch file run python script with arguments - YouTube
Instantly Download or Run this code online at https://codegive.com Certainly! Below is an informative tutorial on creating a batch file to run a Python scrip...
Published   January 18, 2024
Views   336
🌐
Delft Stack
delftstack.com › home › howto › batch › run python file in batch script
How to Run Python File in Batch Script | Delft Stack
March 4, 2025 - If your Python script requires arguments, you can easily pass them through your Batch script. This allows for more dynamic script execution. Here’s how to set it up: Create a Batch file named run_python_with_args.bat.
🌐
Medium
medium.com › @sscswapnil › one-line-of-code-to-write-batch-file-for-python-script-modern-way-971be4b8e73
One line of code to write batch file for Python Script (Modern way). | by Swapnil Chavan | Medium
August 25, 2022 - Meaning of each word provided below: ... %0-%9 refer to the command line parameters of the batch file. %1-%9 refer to command line arguments after the batch file name....
🌐
StackHowTo
stackhowto.com › home › windows 10 › how to run a python script from a batch file
How To Run A Python Script From A Batch File - StackHowTo
January 5, 2026 - %*: Passes all command-line arguments from the batch file to the Python script. pause: Keeps the window open after the script finishes, so you can see the output. Open Notepad. Paste the code above.
🌐
Scresat
scresat.github.io › navigation › Python › 6.+Launching+Python+Programs.html
6. Launching Python Programmes
The %* tells to forward any command line arguments to the python code · Let's run that batch file. We don't need Double Quotation marks(") around the location as there are no space somewhere in between. Notice we use backword slash \ in the command prompt and Run for locating the files instead ...
🌐
Quora
quora.com › How-do-I-enter-values-into-a-running-python-script-in-the-command-line-from-a-bat-file-Im-using-a-batch-file-to-run-a-python-script-The-problem-is-that-the-python-script-that-is-active-in-the-command-shell-then-asks
How do I enter values into a running python script in the command line from a .bat file? I'm using a batch file to run a python script. T...
Answer: It sounds like you’re executing a Python script/program from within an MS Windows batch (.BAT) file and that the Python script is attempting to read data from its standard input files stream, or possibly through a “psuedo-TTY” terminal interface (such as the msvcrt console I/O ...
🌐
Data to Fish
datatofish.com › batch-file-from-python
How to Run a Batch File From Python
Let's say, you want to create a script that runs a batch file located on your desktop, which gets the version number of your system's Windows. ... import os import subprocess path = os.path.expanduser("~/Desktop") + "/ver.bat" subprocess.run(path) After you run this code, the version number of your Windows will be printed to your shell. That's it! You just learned how to run a Windows batch file using Python.
🌐
woteq
woteq.com › home › how to call a python script from a batch file
How to Call a Python Script from a Batch File - Woteq Zone
August 17, 2025 - Now, modify your batch file (run_script.bat) to pass some arguments: @echo off echo Running Python script with arguments... python my_script.py arg1 arg2 arg3 echo Python script completed.
🌐
Automate the Boring Stuff
automatetheboringstuff.com › appendixb
Automate the Boring Stuff with Python
Use the -3 command line argument to make py.exe run the latest Python 3 version installed. Use the cd command to change to the directory (that is, folder) that contains your Python script file. Then use the py program to run your script: C:\Users\Al>cd c:\folderwithyourscript C:\folderwith...
🌐
Penn State University
e-education.psu.edu › geog485 › node › 285
4.5 Automation with batch files and scheduled tasks | GEOG 485: GIS Programming and Software Development
While text wrapping will probably cause this command to be spread across two lines in your browser, it is important that your commands have all the components -- Python path, script path, and parameters -- on the same line. If you copy/paste the example above, you should see those command components all on the same line. If the script takes parameters, you must also type each argument separated by a space. Remember that arguments are the values you supply for the script's parameters. Here's an example of a command that runs a script with two arguments, both strings that represent pathnames.
🌐
Reddit
reddit.com › r/learnpython › executing python script from bat file
r/learnpython on Reddit: Executing Python Script from Bat File
November 27, 2020 -

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 !