在Python中监视进程? [英] Monitor Process in Python?
问题描述
我认为这是一个非常基本的问题,但无论如何都在这里.
I think this is a pretty basic question, but here it is anyway.
我需要编写一个Python脚本来检查以确保某个进程(例如notepad.exe)正在运行.如果该进程正在运行,则什么也不做.如果不是,请启动它.该怎么做.
I need to write a python script that checks to make sure a process, say notepad.exe, is running. If the process is running, do nothing. If it is not, start it. How would this be done.
我在Windows XP上使用Python 2.6
I am using Python 2.6 on Windows XP
推荐答案
有两个选项,
1:更粗略但显而易见的是针对以下内容进行文本处理:
1: the more crude but obvious would be to do some text processing against:
os.popen('tasklist').read()
2:一个更复杂的选择是使用pywin32并研究win32 API以确定正在运行的进程.
2: A more involved option would be to use pywin32 and research the win32 APIs to figure out what processes are running.
3:WMI(我刚刚找到了),并且<一个href ="http://www.computerperformance.co.uk/vbscript/wmi_process.htm" rel ="nofollow noreferrer">这是一个vbscript 示例,说明如何通过WMI在机器上查询进程.
3: WMI (I found this just now), and here is a vbscript example of how to query the machine for processes through WMI.
这篇关于在Python中监视进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!