I want to run a batch file that uses a python script. The python script needs a date as key input.
I tried the following based on what I saw here (Sending arguments from Batch file to Python script)
@echo off
set /p data_valori=Insert date (format yyyy/mm/dd) :
"C:\Program Files\Anaconda3\python.exe" "S:\pricing\Python\new scarico Market Data ASW_PER_DATA_CUSTOM.py" %data_valori%
My python script then does the following:
import sys
data_valori = str(sys.argv[1])
I manage to insert the input in the cmd window but then it never calls python (from what I see) and it just closes the cmd window.
I tried different options for calling python, such as
python new scarico Market Data ASW_PER_DATA_CUSTOM.py %data_valori%
It still closes the cmd after inputting.
set /p data_valori=Insert date (format yyyy/mm/dd) :should really beset /p "data_valori=Insert date (format yyyy/mm/dd) :", its content should be evaluated and validated after the input has been provided, because your end user cannot be expected to only ever follow the prompted format, (deliberately or accidentally).%data_valori%may be better passed as"%data_valori%", and I would have expected that your input would be agument index0, not argument index1.cmd.exewindow will close.data_valori = input("Insert date (format yyyy/mm/dd)"). 2. Btw, to prevent the batch file window from auto-closing after it has finished running, add this at the end:pause(see this answer). 3.sys.argvvalues are always strings, so you don't needstr(sys.argv...).