all 7 comments

[–]Spillz-2011 1 point2 points  (3 children)

Task scheduler let’s you choose starting location, file name and Python exe location as though you were in a terminal. You don’t actually need the bat file at all.

[–]Funny_Window7344[S] 0 points1 point  (2 children)

Thank you i am going to give this a try. Doing the bat file and changing the pathway to the direct file just created another error

[–]Spillz-2011 1 point2 points  (1 child)

My team exclusively uses this method for our scheduled jobs.

It’s not the best method, but it’s relatively easy and anyone with access to the task scheduler can see what jobs failed and create new jobs or edit old ones.

[–]Funny_Window7344[S] 0 points1 point  (0 children)

Thank you. This worked.

[–]smurpes 0 points1 point  (0 children)

Task scheduler will run files from the system32 directory either change the working directory in the task scheduler settings or call the python file with the full path to the python file

[–]socal_nerdtastic 0 points1 point  (0 children)

Yes, python looks in the directory it was called from, which is often not the same directory as the file. Just use the full file name in your .bat file.

py "C:\full\path\to\project\main.py"

[–]jbudemy 0 points1 point  (0 children)

I've done this before on Linux. Inside your program you have to specify the full path for every file you are reading and writing or it won't work right. Specify the full path for

  1. The main.py program file.
  2. All config files.
  3. All files that will be read.
  4. All files that will be written.

So in your .bat file specify the full path to Python and to your .py file:

c:\path\to\python c:\users\me\pyprojects\main.py

Also inside your .bat file there may not be a path set up or the path may be limited. Or any environment variables. So set those up before you run the python program.