简体   繁体   English

如何在Windows 64位平台上的python 2.5中杀死进程?

[英]How to kill a process in python 2.5 on windows 64bit platform?

I have a python script by which i am opening three executable files as follows: 我有一个python脚本,通过它我将打开以下三个可执行文件:

Aa=subprocess.Popen([r"..\location\learning\A.exe"])
Bb=subprocess.Popen([r"..\location\learning\new\B.bat"])
Cc=subprocess.Popen([r"..\location\learning\new\B.bat"])

All the three files are getting opened. 这三个文件都已打开。 Now,next step i want kill these three opened modules.So, firstly i tried to kill "Aa" as follows: 现在,下一步,我要杀死这三个打开的​​模块。因此,首先,我尝试如下杀死“ Aa”:

PROCESS_TERMINATE= 1
k = ctypes.windll.kernel32klll
handle = k.OpenProcess(PROCESS_TERMINATE, False,Aa.pid)
k.TerminateProcess(handle, -1)
k.CloseHandle(handle)

But after adding these piece of lines the three modules 'Aa','Bb' and 'Cc' they don't gets opened.So,i want to know some clean solution so that firstly all the three modules gets executed and then after a while they get closed itself. 但是在添加了这三行代码之后,三个模块'Aa','Bb'和'Cc'并没有打开。当他们自己关闭时。 As,i am using python 2.5 on windows 64 bit platform so kindly suggest solution accordingly. 由于我在Windows 64位平台上使用python 2.5,因此请相应地提出解决方案。

The process returned by subprocess.Popen() has a terminate() method to kill the child process since Python 2.6. subprocess.Popen()返回的进程具有terminate()方法以terminate()子进程(自python 2.6开始)。 To use that you would have to upgrade your Python install or install two versions of Python in parallel. 要使用它,您将必须升级Python安装或并行安装两个版本的Python。

But a better way is usually to find out how you can tell this process to stop and use that. 但是更好的方法通常是找出如何告诉该过程停止并使用它。 Many processes stop when you send them certain standard input or when you close the pipes which Popen created. 当您向他们发送某些标准输入或关闭Popen创建的管道时,许多进程都会停止。

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

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