user979150
user979150

Reputation: 359

Errors trying to run a python script from a batch file

I have this line in my bat file:

C:\Python26\python.exe C:\myPythonDirectory.py

But it fails giving the error: can't open file [Errno2] no such file or directory.

Could it be giving an error because there is a space in one of the folder names in my python directory?

Upvotes: 2

Views: 701

Answers (2)

Saurabh Katti
Saurabh Katti

Reputation: 1

If there are spaces in the names of the directories you need to use the below code. For example, the name of the directory and the path is "D:\My New Bot\main.py" . as there is a gap between the words , python recognises only the first word and tries to find path as "D:\My" which does not exist. Please use the below code :

path = r"D:\My New Bot\main.py"

This will work.

Upvotes: 0

Michael Lorton
Michael Lorton

Reputation: 44436

Absolutely. If there's a space in the path, you need to put the whole path in double quotes.

Upvotes: 2

Related Questions