NOTE:
- using cmd in my profile -working
- using sch.cmd in my profile -working
- using task scheduler running sch.cmd by choosing user is logged in- working
- using task scheduler running sch.cmd by choosing user is logged in or not-NOT WORKING. And also A.py run for some 1 or 2 seconds and then shut down without giving result.
NOTE:
- All files are running using cmd in my profile and fetching correct results.But not with the windows task scheduler in my profile.
- All the permission is already given. I want to list the filename and both methods glob.glob and listdir is not working giving-[ ] empty set or printing nothing at all.
Task scheduler setting:(elastic search is running already and I want to run A.py)
program script:
cmd
arguments:
/c sche.cmd > yash.txt
Start in:
D:\path\
sche.cmd contains:
@echo on
cmd /k "cd /d D:\path\env\Scripts\ & activate & pythonw.exe & cd /d D:\path\files & python A.py"
Now,
NOTE: There is gap in path: '\11.11.11.11\d$\E*ELE In A5*\S\A' but restriction is I just can't change my path as this is path of production.
NOTE: Run with when the user is logged or not AND the highest privileged is enabled.
A.py is:
from elasticsearch import Elasticsearch
import os, glob
import datetime as dt
from datetime import datetime
from dateutil import parser
ES_HOST = {"host": "localhost", "port": 9250}
es = Elasticsearch(hosts=[ES_HOST])
n = 0
a=b=c=d=0
ip = '11.11.11.11'
username = 'abcdefgh'
password = '12345678'
use_dict = {}
use_dict['remote'] = ('\\11.11.11.11\d$\E\ELE In A5\S\A')
use_dict['password'] = ('12345678')
use_dict['username'] = ('abcdefgh')
folder_path = r'\\11.11.11.11\d$\E\ELE In A5\S\A'
print("############", folder_path)
dirContents = os.listdir(r'\\11.11.11.11\d$\E\ELE In A5\S\A')
print("yahoo")
if len(dirContents) == 0:
print('Folder is Empty')
n = 0
else:
print('Folder is Not Empty')
for filename in glob.glob(os.path.join(folder_path, '*')):
with open(filename, 'r', encoding="ISO-8859-1") as f:
text = f.read()
{DO SOMETHING}
**more details are already in unanswered question: **Running python script in Service account by using windows task scheduler****