安排运行Python脚本 [英] Schedule to run Python script

查看:117
本文介绍了安排运行Python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

首先,我将一步一步地进行

1)我想安排python脚本在Windows Scheduler上运行
几个星期前我做到了,我使用bat(.bat)文件来做到这一点,
在bat文件中,
首先执行python exe(.exe),然后将python脚本的路径和参数传递给脚本
例如:-< path of =" python.exe ="> < scriptpath/temp.py> < argument>

该脚本的作用是,在相同位置读取XML文件,以获取一些参数并执行某些操作.在我的C#编码中,我创建XML和bat文件,并且bat的格式如上所述. Python脚本,bat文件和XML文件位于同一位置,我将XML的位置作为参数传递给脚本.

2)我以编程方式将此蝙蝠添加到Windows Scheduler中,并且工作正常,是否满足我的需求

3)然后我创建安装项目并安装

4)现在我可以运行我的应用程序了,它会在执行时在安装文件夹中创建所有必需的文件(XML和bat),bat文件格式也正确.

在调度程序执行时,启动cmd(命令提示符)并启动python解释器和python解释器在几分之一秒后迷路并给出一些消息.但是我无法检查那些...

当我通过VS 2010运行它时,它将创建必要的文件并将bat文件添加到调度程序中,在计划的时间bat文件成功执行.

我的问题是这个,
为什么这个项目在Visual Studio 2010中可以正常运行,而不是作为已安装的程序运行?实际上在计划时间蝙蝠文件执行...

hello,

first i''ll go step by step

1) i want to schedule python script to run on windows scheduler
couple of week ago i did it, i use bat (.bat) file to do this,
in bat file,
first execute python exe (.exe) then pass path of the python script and argument to the script
eg:- <path of="" python.exe=""> <scriptpath/temp.py> <argument>

What this script does is, It''s read XML file on same location to get some parameters and do something. In my C# coding i create XML and bat file and format of bat is described as above. Python script, bat file and XML files are in same location,I pass location of XML as argument to the script.

2) I add this bat into windows scheduler programmatically and it''s working fine, does what i need

3) Then i creates setup project and install it

4) Now i can run my application, it''s create all necessary files in installation folder at execution time (XML and bat), bat file format also correct.

At the scheduler execution time, start cmd(command prompt) and start python interpreter and python interpreter get lost after fraction of second and give some messages.But i cannot check those ...

When i run this through VS 2010 it creates necessary files and add bat file into scheduler, at scheduled time bat file executes successfully.

My question is this,
Why this same project working fine in Visual Studio 2010 and Not as a installed program??? Actually at the schedule time bat file execution...

推荐答案

任务计划程序正在以没有所需权限的用户身份运行它,或者它在运行它时未设置Python需要正确执行的环境变量.

如果您有批处理脚本运行

Either the task scheduler is running it as a user which doesn''t have the permissions it needs, or it is running it without setting the environment variables that Python needs to execute correctly.

If you have your batch script run

python script.py >log.txt



...那么您应该创建一个可以检查的日志文件,并希望该日志文件会提供有用的消息.



... then you should get a log file created that you can inspect and hopefully that will have an informative message.


这篇关于安排运行Python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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