I have a pretty simply python script that steps through all of the feature classes in an enterprise GDB having a certain name. When I run this script from the command line using a .bat file to trigger it, it runs great and completes successfully. 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. Please see code and images below:
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()
When I run the script from the command line using a .bat file:
"C:\Users\?????\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone1\python.exe" "C:\Scripts\ProjectName\ScriptName.py"
I get what I want... The below image shows the log file I write in the above code:

When I run it in the Task Scheduler I get information telling me that the list returned from the arcyp.ListFeatureClasses command is empty:

Another weird thing is that the task always says "Running" in the scheduler even though it has reached the end of the script.
Any thoughts would be appreciated. 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!
K