1

I'm trying to schedule a Python script through Windows Task Scheduler by making a batch file.

Here's what I tried.

  1. Normally putting python location in program/script and specifying the python file in arguments in task scheduler.

  2. Trying through batch file

    start C:\Python27\pythonw.exe C:\Users\...\time_convert.py
    pause
    
    Call C:\Python27\pythonw.exe C:\...\time_convert.py
    pause
    
    C:\Python27\pythonw.exe C:\Users\...\time_convert.py
    pause
    

Also when I run the batch file manually it works fine. But not through task scheduler.

I can see a CMD window pops but a new text file doesn't gets created as per the .py script.

Here's the demo .py script:

print("done")
f=open("ay.txt",'w')
f.write("hi")
f.close()
TylerH
  • 20,799
  • 66
  • 75
  • 101
EXODIA
  • 908
  • 3
  • 10
  • 28
  • The py file has full permission for everyone – EXODIA Apr 10 '19 at 12:58
  • Have you tried to specify the full path to the file, not just a relative path? It could be that the current working directory for the task is different from what you expected. – Ralf Apr 10 '19 at 13:08
  • Are you sure it hasn't written the file, but you're just not looking for it in the correct location? When you run a batch file as a scheduled task, the current working directory is not necessarily the same as when it is run directly or from the Command Prompt. Start by performing a search for the file, `Where/R C:\ ay.txt`, and let us know if it was found. Please also let us know where you want the text file to be located upon completion of the task. – Compo Apr 10 '19 at 13:33
  • This text file was just a example. I wanted to know performing scheduling of python script so I used this file write demo code to know if it is working. Let me search for the file – EXODIA Apr 10 '19 at 13:48
  • It was complete path @Ralf – EXODIA Apr 10 '19 at 13:48
  • @Compo I searched and no such file was found. – EXODIA Apr 10 '19 at 13:54
  • 1
    UPDATE: I solved it by adding a cd command to point to desktop and after that I invoked the python command. I didn't know that current working directory can get changed when we run through task scheduler – EXODIA Apr 10 '19 at 14:09

0 Answers0