Ashim
Ashim

Reputation: 927

Cannot pass an argument from ".bat" file to python script

I am trying to run a python script from my .bat file but I cannot pass the arguments. Please find my code below:

.bat File

set fileDestination = "\home\a\.."
set fileLocation = "\home\b\.."
set fileName = "myFile.xlsx"

"C:\Swdtools\Python3.6.3 X64\Python" fileTransfer.py %fileDestination% %fileLocation% %fileName%

fileTransfer.py

import sys

print(sys.argv[2]) 

The above print statement gives me

IndexError: list index out of range

Upvotes: 1

Views: 355

Answers (1)

jwdonahue
jwdonahue

Reputation: 6669

The space between your variable name and the equal sign becomes part of the name and the space after becomes part of the value. Get rid of the white space:

set fileDestination="\home\a\.."
set fileLocation="\home\b\.."
set fileName="myFile.xlsx"

Upvotes: 1

Related Questions