Skip to content
Advertisement

Running python script in python shell from a windows batch file

I’m trying to run a python script “index.py” in python shell from a .bat file on windows. I tried this first script but it will only open my script in the Python UI without running it :

JavaScript

I tried this second script, but I have issues with os.listdir(relativefolder/) in my python script, as if the relative folder was not calculated from the script location but from the .bat file location

JavaScript

Could you help me find out how to fix this ?

Advertisement

Answer

The second approach is correct.

To solve the import problem you should fix your python code using a different approach: In the following code curdir will have the name of the folder where your script is located, you can work upon this to do what you want.

JavaScript

Or you could change the working directory using the batch script. Check How to change current working directory using a batch file .

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement