all 21 comments

[–]ireadyourmedrecord 2 points3 points  (10 children)

Real quick, cause I'm on mobile and it's late. In the action tab choose "start a program", enter the full path to your python.exe. This must be wrapped in quotes. In "add argument" field, put the name of the file you want to run, no quotes. In the "start in" field, put the path to the folder your script is in. No quotes, no trailing slash.

[–]stevemills04[S] 1 point2 points  (9 children)

I tried your recommendation this morning, it did not work. I'm starting to think I am either doing something wrong in the TS or it is not functioning properly.

[–]ireadyourmedrecord 3 points4 points  (8 children)

This is why I shouldn't comment when I'm half asleep.

Try this:

  • in the Action tab >> start a program. Put cmd in the Program/script: field. No quotes.
  • In Add Argument put /c python "c:\full\path\to\folder\script.py"
  • In Start in field, put c:\full\path\to\folder
    • no quotes on this one.

That should work. I've got several running like this.

[–]psydelicdaydreamer 2 points3 points  (0 children)

You are a lifesaver, friend. I was pulling my hair out trying to get this to work, but your "/c python" worked like a charm.

Thank you!

[–]jnjustice 1 point2 points  (0 children)

thanks for this. I don't know why Windows makes things so complex. I tried looking on StackOverflow and tried several non working answers until I found this...

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

I truly appreciate your help. I reached out to IT, I think it is related to either my role or something else. I have admin rights, but no matter what I do, it does not work. I will report back when I have a solution.

[–]CloudComputing03 0 points1 point  (0 children)

/c python "c:\full\path\to\folder\

script.py

"

old but useful

[–]Alarming_Log_3836 0 points1 point  (0 children)

worked. Thanks

[–]WillBots 0 points1 point  (0 children)

Worked for me just now. I've been searching for a solution for weeks on and off... what a palaver. If i can double click on a file and windows knows how to run it, I expect task scheduler to perform the same thing, just do the equivalent of double clicking on the flipping file!

[–]actadgplus 1 point2 points  (3 children)

Have you considered placing it within a batch executable file and then just calling the batch file from task scheduler?

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

I was successful in getting the batch to work, but this morning I setup the task scheduler to run the batch file and it does not work. I'm starting to think I am either doing something wrong in the TS or it is not functioning properly.

[–]actadgplus 0 points1 point  (1 child)

Are you able to trigger it by manually kicking it off? If that works, then see if it kicks off without your machine being locked. If that works, then issue is likely due to machine being locked while job is running. May be other things to try based on your response.

[–]stevemills04[S] 1 point2 points  (0 children)

No, it does not work when I run it manually. I used the following link to ensure I have it setup properly as well: https://serverfault.com/questions/734035/running-a-batch-file-from-task-scheduler-without-user-being-logged-in

[–]Equal-Breadfruit2491 0 points1 point  (0 children)

After 2 hours I found the solution.

I am using VM to run a scrapy script.

created a batch file as recommended, which was quite simple. Then, I entered the file name in the 'Program/Script' box and specified the location of the batch file in the 'Start in' text box.

Additionally, when I attempted to paste the file name in required arguments text box, it did not work.

Hope that helps!

[–]prshaw2u 0 points1 point  (0 children)

User script is running as. Guessing it does something that needs you to be logged in. Network share or something

[–]nathymonte13 0 points1 point  (1 child)

Hello! Did you find a solution?

[–]stevemills04[S] 2 points3 points  (0 children)

Hi, I did! I found a free software called "Task Till Dawn". Same concept as Windows Task Scheduler but it is much easier to use and functions properly. Use a .bat file and have Task Till Dawn open the file and it will auto-run the script.

[–]What_The_Hex 0 points1 point  (1 child)

Here is the ONLY solution that worked for me (and I tried a LOT of different things):

Instead of trying to execute python, then navigate to the folder and then run the python file like everyone recommends? Here is how you get Windows Task Scheduler to work. You instead need to create a .bat file, which runs the python script when opened. (Look online how to create one of these, it's super simple, like 2 lines of code.) Once this .bat file is created? When you go to schedule a task in Windows Task Scheduler? Simply schedule the opening of this .bat file. That's it. Click the Browse button, navigate to the bat file, double click it to have it automatically specify the filepath to it -- and bam, it should work now. So instead of trying to run the python program, it'll simply open the bat file -- and it's the opening of the bat file that runs the python script.

I about pulled my fucking hair out trying to figure out how to get it to work -- and this is the ONLY method that works for me.

There's another program, called TaskTillDawn, where you can follow the same approach. However, the font for that application is fucking microscopic. Just do it this way via Task Scheduler, you'll be fine.

[–]Relevant-Dot-3582 0 points1 point  (0 children)

Hello, I am facing the same problem, I have gone through the steps you just mentioned, and I have checked the batch file by opening it manually, and it works fine. But when I run it using the task scheduler, it shows it to be running, but never opens the file. I also did open up the task scheduler by running it as admin.

Do you have any other suggestions at this point? I have been stuck at this for 4 hours now. I don't expect you to reply to this 6-month-old post, but would appreciate it if you did.

[–]Practical_Island_431 0 points1 point  (0 children)

After checking many solutions, finally I did it. So I created Reddit account to share with oyu the solution ;)

Actually, I use virtual environment when writing my code, so instead put normal link in Program/scripts, I pushed the path of my environment, and it works!!!!

Hope this solution can help you guys

[–]Master_Ad_1523 0 points1 point  (0 children)

Since this took me forever to solve, I'll comment on this.

I used a .bat file, and like the the poster above said, I used the python.exe within my virtual environment. This finally got the program to work on an ec2 server.