在windows任务计划程序中使用服务帐户运行python脚本会在几秒钟后终止

2024-05-16 08:13:12 发布

您现在位置:Python中文网/ 问答频道 /正文

注意:

  1. 在我的个人资料中使用cmd-工作
  2. 在我的个人资料中使用sch.cmd-工作
  3. 通过选择“用户已登录-工作”,使用运行sch.cmd的任务计划程序
  4. 通过选择用户已登录或未工作,使用运行sch.cmd的任务计划程序。另外,A.py运行约1或2秒,然后关闭而不给出结果

注意:

  1. 所有文件都在我的配置文件中使用cmd运行并获取正确的结果。但我的配置文件中没有windows任务计划程序
  2. 所有的许可都已授予。我想列出文件名,glob.glob和listdir这两种方法都不起作用,即提供-[]空集或根本不打印任何内容

任务计划程序设置:(弹性搜索已在运行,我想运行A.py)

程序脚本:

cmd

参数:

/c sche.cmd > yash.txt

开始于:

D:\path\

sche.cmd包含:

@echo on
cmd /k "cd /d D:\path\env\Scripts\ & activate & pythonw.exe &  cd /d D:\path\files & python A.py"

现在,

注意:路径中存在缺口:'\11.11.11\d$\E*ELE in A5*\S\A',但限制是我无法更改路径,因为这是生产路径

注意:在用户登录或未登录且启用最高权限时运行

A.py是:

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}

**更多细节已在未回答的问题中: **Running python script in Service account by using windows task scheduler****


Tags: path用户pyimport路径程序cmduse