0

My question is related to this, but none of the solutions presented there worked for me. I'm trying to schedule a .py file to run daily using Windows Task Scheduler. The .py file downloads some data and then emails it to someone. I followed the directions here to do this. I can run my .bat file just fine and it downloads the data and emails it.

In Windows Task Scheduler the task is listed as 'Task completed' and also says 'Task Scheduler successfully finished "{7fd6d9a4-82d4-4a43-ba8b-a67a14e17b25}" instance of the "\OBCapacity_SOP" task for user "ANT\user1". However, Last Run Result for the task says '(0x1)' and the data never downloads or gets emailed. Here's how I've set up Task Scheduler for this job in Actions:

Start a Program
Program/script: C:\Users\user1\Documents\COVID19_S&OP\COVID19_SOP.bat
Start in (optional): C:\Users\user1\Documents\COVID19_S&OP\

The task is currently set to only run when user is logged on. Any ideas on how I can fix this problem?

Gaurav Bansal
  • 5,221
  • 14
  • 45
  • 91
  • Where if you were running this from a prompt, you might add print statements to show the flow of the code, make those print statements either logging to a file or sending text directly to a file - then at least you can see what is happening – DisappointedByUnaccountableMod Mar 18 '20 at 22:09
  • It's not clear to me how I'd print out logs in Windows Task Scheduler. The .py script has many print statements that show up when I run the .bat file manually. – Gaurav Bansal Mar 18 '20 at 22:23
  • Open a file at the top of `main()` like `logfile=open(“logfile.txt”,”at”)` and at places where you might use print() do e.g `logfile.write(“starting analysis”)` then you an open logfile.txt in an editor and see what your code did. Or even better setup a logger which logs to a file. – DisappointedByUnaccountableMod Mar 19 '20 at 07:51

0 Answers0