0

NOTE:

  1. using cmd in my profile -working
  2. using sch.cmd in my profile -working
  3. using task scheduler running sch.cmd by choosing user is logged in- working
  4. 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:

  1. All files are running using cmd in my profile and fetching correct results.But not with the windows task scheduler in my profile.
  2. 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****

  • Try debugging it in parts. Does the script run when you run it in e.g. IDLE, does it run from the command line when called directly, does it run when you manually run the list of commands in sche.cmd, does sche.cmd run when you run it directly, does task scheduler show any errors? – JeffUK May 04 '20 at 08:12
  • It runs from cmd, it run when you manually run the list of commands in sche.cmd, sche.cmd run when run it directly, but when i try to run it using task scheduler by selecting the user is logged or not it doesn't give result – YASH KUMAR May 04 '20 at 08:19

0 Answers0