<?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: Python script, when run from Task Scheduler, not returning FC list in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178846#M64681</link>
    <description>&lt;P&gt;I don't have a connection to the office right now, but i will share in the morning (EST). Basically the bat file contains the exe call followed by the bat file name argument as shown above with an ECHO OFF before that line and PAUSE after it, but I really like your idea to call cmd and pass the bat as an argument. I can run the bat from the cmd manually and it works fine. I'll give it a go tomorrow morning and keep you posted.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 31 May 2022 23:37:51 GMT</pubDate>
    <dc:creator>KimberlyGarbade</dc:creator>
    <dc:date>2022-05-31T23:37:51Z</dc:date>
    <item>
      <title>Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178614#M64668</link>
      <description>&lt;P&gt;I have a pretty simply python script that steps through all of the feature classes in an enterprise GDB having a certain name.&amp;nbsp; When I run this script from the command line using a .bat file to trigger it, it runs great and completes successfully.&amp;nbsp; When I embed the same .bat file that runs the script in Windows (10) Task Scheduler, it fails to return a list of FC names.&amp;nbsp; Please see code and images below:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import datetime

f = open ('C:\Scripts\CartegraphIntegration\COJNPDESIntegrationDBLog.txt', 'a+')
f.write("**********Program Started :"+str(datetime.datetime.now())+"**********")
f.write('\n')
# Connection file for ArcPy
CGIntegrationsde = r"z:\Not\A\RealPath\connection.sde"
arcpy.env.workspace = CGIntegrationsde
f.write("Workspace set successfully: " + CGIntegrationsde)
f.write('\n')
#all of the feature classes we want to udpate all start with the word "Spatial"
#but since the names are fully qualified we have to account for other leading characters
featClasses = arcpy.ListFeatureClasses('*Spatial*','','')
f.write("Feature Class List acquired successfully")
f.write('\n')
if not featClasses:
    f.write("The list is empty.")
    f.write('\n')
else:
    for fc in featClasses:
    
        f.write("Updating fields to use appropriate case in FC: " + fc + " :"+str(datetime.datetime.now()))
        f.write('\n')
        
        #Script does something ArcPy like here "edited for privacy

        f.write("Updates complete in FC: " + fc + " :"+str(datetime.datetime.now()))
        f.write('\n')

f.write("**********Completed: "+str(datetime.datetime.now())+"**********")
f.write('\n')
f.close()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;When I run the script from the command line using a .bat file:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;"C:\Users\?????\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone1\python.exe" "C:\Scripts\ProjectName\ScriptName.py"&lt;/LI-CODE&gt;&lt;P&gt;I get what I want... The below image shows the log file I write in the above code:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KimGarbade_0-1654010375055.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/42454iFE75293516291678/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KimGarbade_0-1654010375055.png" alt="KimGarbade_0-1654010375055.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;When I run it in the Task Scheduler I get information telling me that the list returned from the arcyp.ListFeatureClasses command is empty:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KimGarbade_1-1654010421970.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/42455iB71581E30B75A763/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KimGarbade_1-1654010421970.png" alt="KimGarbade_1-1654010421970.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Another weird thing is that the task always says "Running" in the scheduler even though it has reached the end of the script.&lt;/P&gt;&lt;P&gt;Any thoughts would be appreciated.&amp;nbsp; This is really a hassle that it works when I test it and I think I'm just an "Adding it to the scheduler" step away from being done and then that's the part the bails!&lt;/P&gt;&lt;P&gt;K&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 15:37:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178614#M64668</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-05-31T15:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178626#M64671</link>
      <description>&lt;P&gt;Could you confirm what you have in the "Action" tab of the task? Also, is the task running as the same user you're testing with?&lt;/P&gt;&lt;P&gt;Here's a reference to check regarding how to set up the task in Windows Task Scheduler.&lt;BR /&gt;&lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-pro/analytics/schedule-a-python-script-or-model-to-run-at-a-prescribed-time-2019-update/" target="_blank"&gt;Schedule a Python script or model to run at a prescribed time: 2019 update (esri.com)&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 15:54:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178626#M64671</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-05-31T15:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178629#M64672</link>
      <description>&lt;P&gt;Are you connecting to the EGDB as an OS user or a database user?&amp;nbsp; If the former, what credentials is the task running as?&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 15:53:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178629#M64672</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2022-05-31T15:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178632#M64673</link>
      <description>&lt;P&gt;ArcGIS Pro&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KimGarbade_0-1654012553906.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/42458iC0DC00DE9A025B6F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KimGarbade_0-1654012553906.png" alt="KimGarbade_0-1654012553906.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 15:56:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178632#M64673</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-05-31T15:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178638#M64674</link>
      <description>&lt;P&gt;DB Authentication connecting as Data Owner.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm running the task in the Scheduler using my Domain login on my desktop.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 16:03:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178638#M64674</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-05-31T16:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178648#M64675</link>
      <description>&lt;P&gt;Try configuring the task action where the program/script is your Python env exe&lt;/P&gt;&lt;LI-CODE lang="python"&gt;"C:\Users\?????\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone1\python.exe"&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;and the optional argument is the path to your Python script file.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;"C:\Scripts\ProjectName\ScriptName.py"&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 31 May 2022 16:38:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178648#M64675</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-05-31T16:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178674#M64676</link>
      <description>&lt;P&gt;Sorry.&amp;nbsp; I should have mentioned that that was the first way I tried configuring it....&amp;nbsp;&lt;/P&gt;&lt;P&gt;it doesn't seem to have a problem with "import arcpy" or setting the workspace.... just getting the FC list.&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 17:13:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178674#M64676</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-05-31T17:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178791#M64679</link>
      <description>&lt;P&gt;I'm not sure if this will help but maybe worth a try.&amp;nbsp; I call my .bat files a bit differently from the task scheduler.&amp;nbsp; In the "Edit Action" panel:&lt;/P&gt;&lt;P&gt;Action: Start a program&lt;/P&gt;&lt;P&gt;Program/script: cmd&lt;/P&gt;&lt;P&gt;Add Arguments: /c &amp;lt;my bat file name&amp;gt;&lt;/P&gt;&lt;P&gt;Start in (optional): &amp;lt;path to my bat file&amp;gt;&lt;/P&gt;&lt;P&gt;I assume you are running the scheduled task on the same PC as where you run the bat file and your are sure you are running under the same Windows user.&amp;nbsp; Is there any thing non-trivial in your bat file? Maybe you could share that with us too?&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 21:02:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178791#M64679</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-05-31T21:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178846#M64681</link>
      <description>&lt;P&gt;I don't have a connection to the office right now, but i will share in the morning (EST). Basically the bat file contains the exe call followed by the bat file name argument as shown above with an ECHO OFF before that line and PAUSE after it, but I really like your idea to call cmd and pass the bat as an argument. I can run the bat from the cmd manually and it works fine. I'll give it a go tomorrow morning and keep you posted.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 23:37:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178846#M64681</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-05-31T23:37:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178967#M64683</link>
      <description>&lt;P&gt;It runs the script but same result - ListFeatureClasses is still empty.... It must have something to do with ArcPy running in scheduler and the complete lack of error messaging in scheduler (that I know of)... maybe its erroring out setting the workspace I don't even know it.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2022 13:33:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1178967#M64683</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-06-01T13:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1179065#M64686</link>
      <description>&lt;P&gt;Hmmm - very strange.&amp;nbsp; I run a lot of programs with arcpy from the task scheduler and have not seen anything link this.&amp;nbsp; I would try to access one of your feature classes directly (instead of via ListFeatureClasses) - maybe you will get an error message that will be more enlightening that the empty list.&amp;nbsp; You could also do a Describe on the workspace and dump out the results:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;f.write(str(arcpy.da.Describe(CGIntegrationsde)))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2022 16:34:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1179065#M64686</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-06-01T16:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1179123#M64688</link>
      <description>&lt;P&gt;I added the code to describe the workspace and another line to show the path to the python .exe being used when the program is run (on the theory&amp;nbsp; that maybe Scheduler was using a different python.exe than the one intended).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The results are below.&amp;nbsp; The path to the python.exe returned by the script&amp;nbsp; is the same whether it is run from the command line or the scheduler&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;C:\Users\GarbadeK\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone1\python.exe&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So that doesn't seem to be the problem.&amp;nbsp; But the describe of the workspace shows data when run from the command line and shows nothing when run from scheduler.&amp;nbsp; So I think the issue is ArcPy is not being import... even though import ArcPy is the first statement in the script (after&amp;nbsp;# -*- coding: utf-8 -*-).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wonder if its because one of the folders in the python.exe path is hidden?.... I'm just grasping at straws at this point.&lt;/P&gt;&lt;P&gt;I've run Task Scheduler as Admin, run it both as has to be logged in and as not logged in, I have "Use highest permissions" checked.... So close, but yet so far.&lt;/P&gt;&lt;P&gt;K&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2022 18:00:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1179123#M64688</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-06-01T18:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1179483#M64696</link>
      <description>&lt;P&gt;I cracked the case... I'm nothing if not persistent.&amp;nbsp; After writing try/except conditions and examining the description of my workspace (established using a connection file) I determined that Arcpy was indeed loading correctly and that the problem was Arcpy was not establishing a connection to my database using my connection file when my script was run from the scheduler.&amp;nbsp; So, just on a lark, I moved the "connectionfilename.sde" from its current location on a network drive to a location on the C: drive (the same folder the "scriptname.py" file was in).... and Voila it worked.&amp;nbsp; That was at least a day out of my life.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just for the record I tried:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Alternating "Run only when user is logged in" and "Run whether user is logged in or not"&lt;/LI&gt;&lt;LI&gt;Alternating "Run with highest privileges"&lt;/LI&gt;&lt;LI&gt;Running Task Scheduler as "Admin"&lt;/LI&gt;&lt;LI&gt;Running the python script from a batch file&lt;/LI&gt;&lt;LI&gt;Running "path/python.exe" as the "Program/script" with "python path/file" as the argument&lt;/LI&gt;&lt;LI&gt;Running "cmd" as the program and the batch file as the argument&lt;/LI&gt;&lt;LI&gt;Alternating the "Start in" path....&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;All for naught&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I should have thought about the easy solution first, but your keys are always in the last place you look.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 15:17:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1179483#M64696</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-06-02T15:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1179486#M64697</link>
      <description>&lt;P&gt;Glad you got it figured out. See if it works on the network drive using a UNC path rather than a drive letter.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 15:16:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1179486#M64697</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-06-02T15:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1179491#M64698</link>
      <description>&lt;P&gt;Yup. UNC paths worked to...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 15:32:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1179491#M64698</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-06-02T15:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, when run from Task Scheduler, not returning FC list</title>
      <link>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1179580#M64699</link>
      <description>&lt;P&gt;The issue is related to the Environment used by the Windows Scheduler. When Windows starts up, there is a System environment (resources, environment variable, and properties) loaded and used by Windows. Any application, like the Scheduler, that is started by Windows will use this environment unless it is overridden by details from another Windows Account. Modifying the PATH for the Windows system will require a restart of Windows in order for these applications to receive the update. Modifying the PATH for a specific user only requires them to log off and back in.&lt;/P&gt;&lt;P&gt;When starting a Task, if you specify an account other than system, the task will use the user environment details from that account. Similar to environment variables, a user's mounted drives like your "M:", will not be available to the scheduled task unless you include provisions to mount it. The BAT script can mount a network drive by using 'net use M \\&amp;lt;server&amp;gt;\&amp;lt;folder&amp;gt;' before it launches the Python script.&lt;/P&gt;&lt;P&gt;Setting the ArcPy workspace to a folder does not mean that it will be accessible unless the path really exists.&lt;/P&gt;&lt;P&gt;You have to think about a Scheduled Task as a separate login session, not the same session you created it from.&lt;/P&gt;&lt;P&gt;I hope this helps...&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 18:36:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-when-run-from-task-scheduler-not/m-p/1179580#M64699</guid>
      <dc:creator>PDodd</dc:creator>
      <dc:date>2022-06-02T18:36:36Z</dc:date>
    </item>
  </channel>
</rss>

