我打开了三个进程,然后我杀死了所有三个进程,如下所示:
import subprocess
DETACHED_PROCESS = 0x00000008
Process1 = subprocess.Popen("C:\learning\A.exe",creationflags=DETACHED_PROCESS,shell=True)
print"process id :",Process1.pid
Process2 = subprocess.Popen("D:\develop\B.exe", creationflags=DETACHED_PROCESS,shell=True)
print"process id :",Process2.pid
Process3 = subprocess.Popen("D:\testing\C.exe", creationflags=DETACHED_PROCESS,shell=True)
print"process id :",Process3.pid
terminate_process1 = subprocess.call(['taskkill', '/F', '/T', '/PID', A.exe])
terminate_process2 = subprocess.call(['taskkill', '/F', '/T', '/PID', B.exe])
terminate_process3 = subprocess.call(['taskkill', '/F', '/T', '/PID', C.exe])
我正在获取所有三个打开的 exe 的进程 ID,以同样的方式我希望打印已终止进程的进程 ID,以确认打开的进程已成功终止。当我在命令提示符下运行它时,我确实终止了进程 ID,但是如果我在其他地方运行此脚本,例如在 python shell 上,那么我不会得到终止的进程 ID。因此,建议我在打印的输出中获取终止的进程 ID。