在激活脚本后尝试使用subprocess.kill(),但是它不起作用

时间:2019-10-24 11:33:06

标签: python bash subprocess

我正在通过cmd运行python脚本,这将打开一个运行bash脚本的新外壳。问题是我还需要杀死它...

我尝试使用subprocess.kill() subprocess.terminate() 乃至 os.system("taskkill /F /pid "+str(p.pid)) 可以回馈

SUCCESS: The process with PID 11508 has been terminated.

没有发生。

我的代码是这样的: 相关的python行是

p = Popen(['C:/cygwin64/bin/bash.exe', '-c', '. /etc/profile; /cygdrive/c/Users/user/Desktop/host_manager/ba.sh'], creationflags=CREATE_NEW_CONSOLE)

ba.sh是

#! /bin/bash
`. /etc/profile`
/home/user/rc64_host_server.exe -in 50001 -out 50002 -d 1 -dsn 14993-0050

exe是侦听的ssh服务器。

顺便说一句,当我运行

p = Popen('C:/cygwin64/bin/bash.exe', creationflags=CREATE_NEW_CONSOLE)

杀人成功完成任务。

如何使用脚本杀死子进程?

0 个答案:

没有答案