Run Python script through Windows Task Scheduler

2243
3
05-02-2012 05:09 AM
MathieuCain
New Contributor III
Hello,

I have a number of Python scripts (exported models from Model Builder), which I would like to get run automatically at a particular time/day of the week. I had hoped I could run the scripts through MS Access so as to bundle them up with a number of other procedures that happen first there, and then schedule a basic MS Access macro to run through Windows Task Scheduler. Unfortunately, I have had limited success in getting the scripts to run through Access ShellWait.

I would appreciate your help.

Thanks.
Tags (2)
0 Kudos
3 Replies
BruceNielsen
Occasional Contributor III
If your scripts reference data on a network drive (like N:\folder\...), you will need to use the drive's UNC name (\\server\share\folder\...) instead.
0 Kudos
MathieuCain
New Contributor III
If your scripts reference data on a network drive (like N:\folder\...), you will need to use the drive's UNC name (\\server\share\folder\...) instead.


Thank you for your reply.

I take it you are referring to changing the Local variables defined in the python script (previously exported from Model Builder). However, then what? Should I be creating a separate "master" script, which calls all of the other individual python scripts, and gets run in Windows Task Manager through something like "C:\Python26\ArcGIS10.0\python.exe" "\\servername\Data\MyDocumentPath\master.py" (i.e., Program/script: "C:\Python26\ArcGIS10.0\python.exe"; Add arguments (optional): "\\servername\Data\MyDocumentPath\master.py")

This would be as opposed to trying to find a way to include the scripts in an MS Access macro, run through a ShellWait.
0 Kudos
MichaelVolz
Esteemed Contributor
I would create a bat file such as this that would call the python script(s) that you created.  I have additional documentation that is sent to the log file to help indentify when each script is being run.  Just give it a file name such as Update.bat


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

echo ------------  Start time: %time%
echo ------------  Refreshing Database  -----------------------
echo ------------  Refreshing Database  ----------------------- >> update_data.log
01_Data.py >> update_data.log

echo End time: %time%
echo  ' ' >> update_data.log
echo End time: %time% >> update_data.log
@echo on

I hope this helps.
0 Kudos