Select to view content in your preferred language

Python &  Windows Task Scheduler

3489
8
09-27-2012 02:07 PM
StephaniePatterson
Deactivated User
I have created a python script and am using Windows 7 Task Scheduler because I want it to run daily. It runs fine if I run it manually or 'Run only when user is logged on'. I am running into trouble when I choose 'Run only whether user is logged on or not'. I have read several form entries and have employed the following solutions:

-Changed all paths to UNC paths in my python script
-Put it into a .Bat file

Does anyone have a solution to this? This seems like it should be so simple.

~Stephanie Patterson
Tags (2)
0 Kudos
8 Replies
by Anonymous User
Not applicable
When you created a new scheduled task, did you check the "Wake Computer Up to Run this task" box under the settings tab?  Also, when you create a .bat file, how did you set up?  I usually just set up batch files by opening up notepad and just putting something like this in and saving it as .bat file:

start G:\Misc\Scripts\Backup_mdb.py


OR

you can just navigate to your .py file on the Run: line under the task tab.

[ATTACH=CONFIG]18064[/ATTACH]
0 Kudos
StephaniePatterson
Deactivated User
I found 'Wake the computer to run this task" under the Conditions Tab and I checked that on. What I have in my .bat file looks like this:

start I:\GIS\ArcGISServer\Probation\Updates_Daily\PythonScripts\GeocortexDailyUpdate_new.py


I ran it with 'Run whether user is logged on or not' to no success. It just keeps running without completing like it would if I had is set to 'Run only when user is logged on'. Any other ideas?
0 Kudos
ChristopherThompson
Frequent Contributor
can you try running the script directly rather than from a bat? we run a number of scripts that fire as frequently as ever 5 minutes up to an hour or just once a day, and the tasks are refered to directly and run just fine.  To do this, when you are editing the Actions that are carried out by the task under the Action drop down, select 'Start a program' and under the settings, where it is asking for the program or script to run we have 'C:\Python26\ArcGIS10.0\pythonw.exe' and then the script path/file name is supplied in the text box that asks for arguments. See the attached image.
0 Kudos
StephaniePatterson
Deactivated User
I changed to run the python script itself. It runs but then completes like in 2 seconds not running my script but says it ran successfully, but it didnt.
0 Kudos
MichaelVolz
Esteemed Contributor
Here is a bat file I have that runs the .py script below and includes writing to a log file from both the bat file and the py script.  You should also check Run with highest privileges:


@echo off
echo Start time: %time% > Road_Index_Update.log

echo ------------  Update time: %time%
echo ------------  Create Road Index  -------------
echo ------------  Create Road Index  ------------- >> Road_Index_Update.log
Feature_Class_for_Road_Index.py >> Road_Index_Update.log

echo End time: %time%
echo  ' ' >> Road_Index_Update.log
echo End time: %time% >> Road_Index_Update.log
@echo on
0 Kudos
by Anonymous User
Not applicable
I am running into the same problem as the OP ... I cannot get a python script to run with Windows 7 Task Scheduler when I check 'Run only whether user is logged on or not' ... however, the script will run perfectly fine when 'Run only when user is logged on' is checked.  Also, checking 'Run with highest privileges' seems to have no effect.

This has got me stumped...

As the OP has already mentioned, it seems like the remedy to this problem should be something easy...
0 Kudos
curtvprice
MVP Alum
I would add a little tweak to capture the error messages if any. Also, the way to enter a blank line - no quotes is: "echo.":

@echo off
echo Start time: %time% > Road_Index_Update.log
echo ------------  Update time: %time%
echo ------------  Create Road Index  -------------
echo ------------  Create Road Index  ------------- >> Road_Index_Update.log
Feature_Class_for_Road_Index.py >> Road_Index_Update.log 2>&1 
echo End time: %time%
echo. >> Road_Index_Update.log
echo End time: %time% >> Road_Index_Update.log


The issue of things not working when not logged in may be a Windows permissions setting. (That's why it was suggested you run at the highest permission account you have access to.)
0 Kudos
AndrewChapkowski
Esri Regular Contributor
I find checking 'Run with highest privileges' needs to be checked on Windows 7 for scheduled tasks.
0 Kudos