使用Windows Task Scheduler在Service帐户中运行python脚本 [英] Running python script in Service account by using windows task scheduler

查看:84
本文介绍了使用Windows Task Scheduler在Service帐户中运行python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意1-所有文件都在我的配置文件中使用cmd运行并提取正确的结果.但是Windows任务计划程序却没有.

NOTE 1- All files are running using cmd in my profile and fetching correct results.But not with the windows task scheduler.

**>注2-我终于得到了一个线索,表明glob.glob和os.listdir不是

**> NOTE 2- I finally got a lead that glob.glob and os.listdir is not

在我的python脚本中的Windows Task Scheduler中工作正在建立与远程服务器的连接,但它在我的服务器上正常工作本地使用cmd和pycharm.****

working in the windows task scheduler in my python script in which I am making a connection to a remote server, but it is working in my local using cmd and pycharm.** **

print("before for loop::", os.path.join(file_path, '*')) 
print(glob.glob( os.path.join(file_path, '*') ))
for filename in glob.glob( os.path.join(file_path, '*') ):
print("after for loop")

**在.py脚本上运行时,我得到: for循环之前:: c:\ users \ path \ dir \ * 在执行 print(glob.glob(os.path.join(file_path,'*')))时给出"[]" 却找不到原因?

** While running above .py script I got: before for loop:: c:\users\path\dir\* While executing print(glob.glob( os.path.join(file_path, '*') )) giving "[]" and not able to find why?

我遵循了此StackOverflow链接,以通过参考MagTun注释为python设置Windows Scheduler:

I followed this StackOverflow link for setting up Windows Scheduler for python by referring to MagTun comment:Scheduling a .py file on Task Scheduler in Windows 10

  1. 当前,我有 scheduler.py ,它正在调用另外4个.py文件.

  1. Currently, I am having scheduler.py which is calling the other 4 more .py files.

当我尝试从Windows Task SCHEDULER运行 Scheduler.py 时,

When I try to run Scheduler.py from Windows Task SCHEDULER,

它运行Scheduler.py,然后在1分钟后运行所有其他4个.py文件,并在一秒钟内退出.在弹性搜索中未提供任何输出.

It runs Scheduler.py and then after 1 minute it runs all other 4 .py files and exit within a seconds. Not giving any output in elastic search.

我将其用于cmd脚本:

I used this for cmd script:

 @echo off
cmd /k "cd /d D:\folder\env\Scripts\ & activate &  cd /d D:\folder\files & python scheduler.py" >> open.log

timeout /t 15

在上面的cmd命令中,使用Windows任务计划程序运行时,它不会在open.log中保存任何内容.

In this above cmd command, It is not saving anything in open.log when running with windows task scheduler.

具有多个.py子流程调度程序的脚本如下:

from apscheduler.schedulers.blocking import BlockingScheduler
import datetime
from subprocess import call
from datetime import datetime
import os
from apscheduler.schedulers.blocking import BlockingScheduler

def a():
    call(['python', r'C:\Users\a.py'])

def b():
    call(['python', r'C:\Users\b.py'])

def c():
    call(['python', r'C:\Users\c.py'])

def d():
    call(['python', r'C:\Users\d.py'])

if __name__ == '__main__':
    scheduler = BlockingScheduler()
    scheduler.add_job(a, 'interval', minutes=1)
    scheduler.add_job(b, 'interval', minutes=2)
    scheduler.add_job(c, 'interval', minutes=1)
    scheduler.add_job(d, 'interval', minutes=2)
    print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
    try:
        scheduler.start()
        print("$$$$$$$$$$$$$$$$$$")
    except (KeyboardInterrupt, SystemExit):
        print("****#####")
        pass

推荐答案

具有相同的怪异问题.当以用户身份运行时,其工作原理像一个超级按钮.使用Windows任务时,全局查询将不返回任何结果.

Having the same bizar issue. Works like a charm when running as user. With a windows task the glob query returns no results.

正在使用其映射名称表示的网络共享.仅在使用完整的UNC路径(包括服务器名称)时有效.

was using a network share by its mapping name. Only works when using the full UNC path (including the server name).

这篇关于使用Windows Task Scheduler在Service帐户中运行python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆