How to terminate a python subprocess launched with shell=True

前端 未结 12 2704
轮回少年
轮回少年 2020-11-21 04:53

I\'m launching a subprocess with the following command:

p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)

However, when I try t

12条回答
  •  南方客
    南方客 (楼主)
    2020-11-21 05:04

    I could do it using

    from subprocess import Popen
    
    process = Popen(command, shell=True)
    Popen("TASKKILL /F /PID {pid} /T".format(pid=process.pid))
    

    it killed the cmd.exe and the program that i gave the command for.

    (On Windows)

提交回复
热议问题