如何安排 Python 脚本在 Windows XP 运行时运行?
我编写了一个温度记录器Python脚本,并将其作为Windows XP中的计划任务输入。它具有以下命令行:
C:\Python26\pythonw.exe "C:\path\to\templogger.py"
它将数据写入本地公共文件夹中的文件(例如,所有本地登录的人都可以完全访问)。
到目前为止,我已经实现了这个目标:
1. 让任务在任何人登录之前运行(即在“按 Ctrl+Alt+Del”屏幕)
但我遇到了这些问题:
1. 当我登录、注销然后重新登录时,计划任务不再处于活动状态。我无法再在任务管理器的“进程”选项卡中看到它。我怀疑当我注销时它会关闭。
2. 我尝试将任务的“运行方式...”属性设置为 DOMAIN\my-username
并尝试了 SYSTEM
,但上述问题 #1 仍然存在。
摘要:
我希望只要 Windows 处于活动状态,我的程序就可以运行。无论是否有人登录或退出都无关紧要。
PS
我问
I wrote a temperature logger Python script and entered it as a scheduled task in Windows XP. It has the following command line:
C:\Python26\pythonw.exe "C:\path\to\templogger.py"
It writes data to a file in local public folder (e.g. fully accessible by all who login locally).
So far, I was able to achieve this objective:
1. Get the task to run even before anyone logs in (i.e. at the "Press Ctrl+Alt+Del" screen)
But I'm having problems with these:
1. When I log in, log out, then log back in, the scheduled task is no longer active. I can no longer see it in the Task Manager's Processes tab. I suspect it closes when I log out.
2. I tried to set the task's "Run As..." property to DOMAIN\my-username
and also tried SYSTEM
, but problem #1 above still persists.
SUMMARY:
I want my program to be running as long as Windows is active. It should not matter whether anyone has logged in or out.
P.S.
I asked the same question in Super User, and I was advised to write it as a service, which I know nothing about (except starting and stopping them). I hope to reach a wider audience here at SO.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是否可以运行Python脚本作为 Windows 中的服务?如果可能,如何实现?
http:// /agiletesting.blogspot.com/2005/09/running-python-script-as-windows.html
Is it possible to run a Python script as a service in Windows? If possible, how?
http://agiletesting.blogspot.com/2005/09/running-python-script-as-windows.html
您的场景正是服务所需的用例,不幸的是任务不适合您想要做的事情。也就是说,用 python 编写服务也不是在公园里散步,为了减轻痛苦,这里有一些我过去仔细阅读过的链接:
http://agiletesting.blogspot.com/2005/09/running-python-script-as-windows.html
http://mail.python.org/pipermail/python-win32/ 2008-April/007298.html
我特别使用第二个链接来创建一个 Windows 脚本,然后使用 py2exe 将其编译为可执行服务并使用 SrvAny 进行安装。
Your scenario is exactly the required use case for a service, unfortunately tasks are ill suited for what you are looking to do. That said writing services in python is not a walk in the park either, to ease the pain here is a few links I have perused in the past:
http://agiletesting.blogspot.com/2005/09/running-python-script-as-windows.html
http://mail.python.org/pipermail/python-win32/2008-April/007298.html
I used the second link in particular to create a windows scripts that was then compiled to a executable service with py2exe and installed with SrvAny.