我正在使用以下命令启动子进程:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用时杀死:
p.terminate()
Run Code Online (Sandbox Code Playgroud)
要么
p.kill()
Run Code Online (Sandbox Code Playgroud)
该命令在后台继续运行,所以我想知道如何实际终止该进程.
请注意,当我运行命令时:
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
Run Code Online (Sandbox Code Playgroud)
它在发出时会成功终止p.terminate().
我一直试图杀死一个进程,但是我所有的选择都给了我Windows Access Denied Error。我通过打开进程(一个python脚本)test= subprocess.Popen([sys.executable, "testsc.py"]),我想杀死该进程。
到目前为止,我已经试过os.kill(pid, signal.SIGILL),os.kill(pid, 9),test.Terminate()和简单test.kill()。所有这些给了我错误。
我在Windows 7 x86计算机上使用Python 2.7.1.4。我将不胜感激!谢谢!