<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Task scheduler with batch file running python script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1474568#M70607</link>
    <description>&lt;P&gt;Dominic:&lt;/P&gt;&lt;P&gt;Have this migrated this script to use ArcGIS Pro's version of python as compared to ArcMap's version of python?&lt;/P&gt;</description>
    <pubDate>Fri, 17 May 2024 14:38:50 GMT</pubDate>
    <dc:creator>MikeVolz</dc:creator>
    <dc:date>2024-05-17T14:38:50Z</dc:date>
    <item>
      <title>Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107538#M62633</link>
      <description>&lt;P&gt;Have created a script and a batch file to run the process automatically.&lt;/P&gt;&lt;P&gt;Pywin opens the script does not"&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help in getting it to open and execute would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Batch file as follows&lt;/P&gt;&lt;P&gt;C:\Python27\ArcGIS10.6\Lib\site-packages\pythonwin\Pythonwin.exe&lt;BR /&gt;C:\Users\jstout\Desktop\PY\MorningProcess\morningprocess.py&lt;BR /&gt;Timeout 15&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Script as follows&lt;/P&gt;&lt;P&gt;import arcpy, arceditor, time, smtplib&lt;/P&gt;&lt;P&gt;# Set the workspace&lt;BR /&gt;arcpy.env.workspace = r'C:\Users\jstout\AppData\Roaming\ESRI\Desktop10.6\ArcCatalog\EED_FM@SDE.sde'&lt;/P&gt;&lt;P&gt;# Set a variable for the workspace&lt;BR /&gt;adminConn = arcpy.env.workspace&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;database = "Database Connections/toolboxDEFAULTVersion.sde"&lt;BR /&gt;versions = arcpy.ListVersions(adminConn)&lt;/P&gt;&lt;P&gt;# Print the versions available to the user&lt;BR /&gt;for version in versions:&lt;BR /&gt;print(version)&lt;BR /&gt;print "Version list complete."&lt;/P&gt;&lt;P&gt;# Execute the ReconcileVersions tool.&lt;BR /&gt;# Use a list comprehension to get a list of version names where the owner&lt;BR /&gt;# is the current user and make sure sde.default is not selected.&lt;BR /&gt;print 'Reconcile versions started.'&lt;/P&gt;&lt;P&gt;verList = [ver.name for ver in arcpy.da.ListVersions() if ver.isOwner&lt;BR /&gt;== True and ver.name.lower() != 'sde.EFAULT']&lt;/P&gt;&lt;P&gt;arcpy.ReconcileVersions_management(adminConn, "ALL_VERSIONS", "SDE.DEFAULT", "", "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST","DELETE_VERSION")&lt;/P&gt;&lt;P&gt;# Write messages to a Text File&lt;BR /&gt;txtFile = open("c:\\temp\\GPMessages.txt","w")&lt;BR /&gt;txtFile.write (arcpy.GetMessages())&lt;BR /&gt;txtFile.close()&lt;/P&gt;&lt;P&gt;print ('see error log at "c:\temp\GPMessages.txt"')&lt;BR /&gt;print'Reconciling Complete'&lt;/P&gt;&lt;P&gt;# Run the compress tool.&lt;BR /&gt;print("Running compress")&lt;BR /&gt;arcpy.Compress_management(adminConn)&lt;/P&gt;&lt;P&gt;# Use a connection file to create the connection&lt;BR /&gt;print "Check state ID"&lt;BR /&gt;egdb = r'C:\Users\jstout\AppData\Roaming\ESRI\Desktop10.6\ArcCatalog\EED_FM@SDE.sde'&lt;BR /&gt;egdb_conn = arcpy.ArcSDESQLExecute(egdb)&lt;/P&gt;&lt;P&gt;table_name = 'EED_FM.sde.sde_States'&lt;BR /&gt;field_name = 'state_id'&lt;/P&gt;&lt;P&gt;sql = '''&lt;BR /&gt;SELECT {0}, COUNT({0}) AS f_count FROM {1}&lt;BR /&gt;GROUP BY {0}&lt;BR /&gt;ORDER BY f_count DESC&lt;BR /&gt;'''.format(field_name, table_name)&lt;/P&gt;&lt;P&gt;egdb_return = egdb_conn.execute(sql)&lt;BR /&gt;for i in egdb_return:&lt;BR /&gt;print('{}: {}'.format(*i))&lt;BR /&gt;print "State count complete"&lt;/P&gt;&lt;P&gt;# Update statistics and indexes for the system tables&lt;BR /&gt;# Note: to use the "SYSTEM" option the user must be an geodatabase or database administrator.&lt;BR /&gt;# Rebuild indexes on the system tables&lt;BR /&gt;print("Rebuilding indexes on the system tables")&lt;BR /&gt;arcpy.RebuildIndexes_management(adminConn, "SYSTEM")&lt;/P&gt;&lt;P&gt;# Update statistics on the system tables&lt;BR /&gt;print("Updating statistics on the system tables")&lt;BR /&gt;arcpy.AnalyzeDatasets_management(adminConn, "SYSTEM")&lt;/P&gt;&lt;P&gt;print("Finished.")&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 14:55:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107538#M62633</guid>
      <dc:creator>JamesStout101</dc:creator>
      <dc:date>2021-10-14T14:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107557#M62635</link>
      <description>&lt;P&gt;Does the script run manually? Are you getting any error messages?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 15:29:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107557#M62635</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-10-14T15:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107566#M62636</link>
      <description>&lt;P&gt;The script does run manually. I can open it in py win and run it runs ok. The problem is making it run on a scheduled task.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 15:49:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107566#M62636</guid>
      <dc:creator>JamesStout101</dc:creator>
      <dc:date>2021-10-14T15:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107569#M62637</link>
      <description>&lt;P&gt;I am not familiar with py win, so I'm not sure how that may or may not be playing into things.&lt;/P&gt;&lt;P&gt;When your batch script calls the .py file, how does py win know to look for that? Should the script's filepath be an argument on the same line, after opening the program&lt;/P&gt;&lt;P&gt;For what it's worth, we use &lt;STRONG&gt;conda&lt;/STRONG&gt;, and schedule our scripts as follows:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;call c:\ProgramData\Anaconda3\Scripts\activate.bat
conda activate &amp;lt;env-name&amp;gt; &amp;amp;&amp;amp; python &amp;lt;script-filepath&amp;gt;&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 14 Oct 2021 16:03:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107569#M62637</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-10-14T16:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107588#M62638</link>
      <description>&lt;P&gt;Perhaps you could try this format in your BAT file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"C:\Python27\ArcGIS10.6\python.exe" "&lt;SPAN&gt;C:\Users\jstout\Desktop\PY\MorningProcess\morningprocess.py&lt;/SPAN&gt;"&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 16:56:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107588#M62638</guid>
      <dc:creator>DominicRobergeIADOT</dc:creator>
      <dc:date>2021-10-14T16:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107591#M62639</link>
      <description>&lt;P&gt;I've never been able to get a scheduled task to execute properly from a desk top computer; only a server.&amp;nbsp; These other responses sound like great suggestions.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 17:05:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107591#M62639</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-10-14T17:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107598#M62640</link>
      <description>&lt;P&gt;Placing the argument on same line opened the script it does not execute.&lt;/P&gt;&lt;P&gt;PyWin and the script both open task doesn't run.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 17:21:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107598#M62640</guid>
      <dc:creator>JamesStout101</dc:creator>
      <dc:date>2021-10-14T17:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107601#M62641</link>
      <description>&lt;P&gt;Command prompt sits there nothing runs. The command shows in the window as above.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 17:28:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107601#M62641</guid>
      <dc:creator>JamesStout101</dc:creator>
      <dc:date>2021-10-14T17:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107606#M62642</link>
      <description>&lt;P&gt;humm interesting. Can You open the py file using the IDLE try to run it see if you are getting any error messages. (right click on the file and select Edit with IDLE). I use this all the time and it works on desktop and servers&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DominicRoberge2_0-1634232690070.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25217iCE49C086758C9D27/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DominicRoberge2_0-1634232690070.png" alt="DominicRoberge2_0-1634232690070.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 17:32:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107606#M62642</guid>
      <dc:creator>DominicRobergeIADOT</dc:creator>
      <dc:date>2021-10-14T17:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107615#M62643</link>
      <description>&lt;P&gt;Error&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "C:\Users\jstout\Desktop\PY\MorningProcess\MorningProcess.py", line 1, in &amp;lt;module&amp;gt;&lt;BR /&gt;import arcpy, arceditor, time, smtplib&lt;BR /&gt;ModuleNotFoundError: No module named 'arcpy'&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 17:56:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107615#M62643</guid>
      <dc:creator>JamesStout101</dc:creator>
      <dc:date>2021-10-14T17:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107624#M62644</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;look at this link in the Paths and import section&lt;/P&gt;&lt;P&gt;&lt;A href="https://desktop.arcgis.com/en/arcmap/10.6/analyze/python/importing-arcpy.htm" target="_blank"&gt;https://desktop.arcgis.com/en/arcmap/10.6/analyze/python/importing-arcpy.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DominicRoberge2_0-1634234753683.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25219iC61DA1D7B36F577D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DominicRoberge2_0-1634234753683.png" alt="DominicRoberge2_0-1634234753683.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 18:06:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107624#M62644</guid>
      <dc:creator>DominicRobergeIADOT</dc:creator>
      <dc:date>2021-10-14T18:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107627#M62645</link>
      <description>&lt;P&gt;Using 10.6 have none of these lines.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 18:13:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107627#M62645</guid>
      <dc:creator>JamesStout101</dc:creator>
      <dc:date>2021-10-14T18:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107630#M62646</link>
      <description>&lt;P&gt;you still should have&amp;nbsp;C:\Python27\ArcGIS10.6\Lib\site-packages&lt;/P&gt;&lt;P&gt;then open the&amp;nbsp;Desktop10.6.pth with notepad&lt;/P&gt;&lt;P&gt;I am using 10.8 and got this&lt;/P&gt;&lt;P&gt;C:\Python27\ArcGIS10.8\Lib\site-packages\Desktop10.8.pth&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DominicRoberge2_0-1634235488713.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25220iD9F3791647B42596/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DominicRoberge2_0-1634235488713.png" alt="DominicRoberge2_0-1634235488713.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 18:18:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1107630#M62646</guid>
      <dc:creator>DominicRobergeIADOT</dc:creator>
      <dc:date>2021-10-14T18:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1474568#M70607</link>
      <description>&lt;P&gt;Dominic:&lt;/P&gt;&lt;P&gt;Have this migrated this script to use ArcGIS Pro's version of python as compared to ArcMap's version of python?&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 14:38:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1474568#M70607</guid>
      <dc:creator>MikeVolz</dc:creator>
      <dc:date>2024-05-17T14:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1474744#M70613</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/465276"&gt;@MikeVolz&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I use the following line to run python script using AGS Pro and task scheduler&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DominicRoberge2_0-1715973463739.png" style="width: 765px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/104519i250A0CBC64476A51/image-dimensions/765x62?v=v2" width="765" height="62" role="button" title="DominicRoberge2_0-1715973463739.png" alt="DominicRoberge2_0-1715973463739.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 19:18:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1474744#M70613</guid>
      <dc:creator>DominicRobergeIADOT</dc:creator>
      <dc:date>2024-05-17T19:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Task scheduler with batch file running python script</title>
      <link>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1475370#M70620</link>
      <description>&lt;P&gt;Dominic:&lt;/P&gt;&lt;P&gt;I have tried this technique besides calling a custom bat file thru Windows Task Scheduler and the import arcpy call using python 3.x installed with Pro randomly crashes.&amp;nbsp; As such this is not a reliable solution for my org.&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 13:36:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/task-scheduler-with-batch-file-running-python/m-p/1475370#M70620</guid>
      <dc:creator>MikeVolz</dc:creator>
      <dc:date>2024-05-20T13:36:54Z</dc:date>
    </item>
  </channel>
</rss>

