简体   繁体   English

将.bat文件转换为Windows计划任务操作

[英]Converting a .bat file into a Windows Scheduled Task Action

I currently have a .bat file with this code that is called by a windows scheduled task, and it runs perfectly ( note I am not running the entire py script, just a function from within): 我目前有一个.bat文件,该文件由Windows计划任务调用,并且运行良好( 请注意,我没有运行整个py脚本,而只是内部的一个函数):

SET PATH=c:\python27\ArcGIS10.5\;c:\Windows\system32\;C:\Python27\ArcGIS10.5\Scripts
python -c "import sys;sys.path.append(r'\\moss\scripts\Automated');import dbAudit;dbAudit.propInsDate()"

I am trying to remove the need for all my tasks to rely on .bat files, when the .py file resides in the same directory, and it is perfectly callable. 当.py文件位于同一目录中并且可以完全调用时,我试图消除所有任务依赖于.bat文件的需要。

Just as an initial stab in the dark I have tried adding this to the Program/Script box: 就像在黑暗中的初始刺伤一样,我尝试将其添加到“程序/脚本”框中:

C:\Windows\System32\cmd.exe

and then added this to the arguments box: 然后将其添加到参数框中:

python -c "import sys;sys.path.append(r'\\moss\scripts\Automated');import dbAudit;dbAudit.propInsDate()"

This seems to fail, as I don't think my conversion is that simple, and I can see i have not included any of the 'set path' items. 这似乎失败了,因为我认为我的转换不是那么简单,并且可以看到我没有包含任何“设置路径”项。

Do you think that my bat file is able to be taken out of the equation and it can all be done directly in the Windows Scheduled Task? 您是否认为我的bat文件可以从公式中取出,并且可以直接在Windows Scheduled Task中完成?

Thanks for your assistance. 谢谢你的协助。

eryksun has provided the correct answer, but has posted it as a comment, so I cannot mark it as the correct answer, so I will paste his reply here: eryksun提供了正确的答案,但已将其发布为评论,因此我无法将其标记为正确的答案,因此我将在此处粘贴他的答复:

You don't need the CMD shell at all. 您根本不需要CMD外壳。 Use the fully-qualified path to python.exe, and the arguments could be, for example, 使用python.exe的标准路径,例如,参数可以是

-c "import os, sys; os.environ['PATH'] += r'C:\\Python27\\ArcGIS10.5;C:\\Python27\\ArcGIS10.5\\Scripts'; sys.path.append(r'\\moss\\scripts\\Automated'); import dbAudit; dbAudit.propInsDate()" -c“ import os,sys; os.environ ['PATH'] + = r'C:\\ Python27 \\ ArcGIS10.5; C:\\ Python27 \\ ArcGIS10.5 \\ Scripts'; sys.path.append(r'\\ moss \\ scripts \\ Automated');导入dbAudit; dbAudit.propInsDate()“

– eryksun Jul 20 at 1:52 – eryksun 7月20日在1:52

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM