i am trying to invoke a command prompt and run some commands on it. However when i am trying to close it through kill() or terminate () , the cmd window does not get closed
Below is my code
from subprocess import Popen, CREATE_NEW_CONSOLE
test=Popen(["cmd","/K","appium -p 4723"],creationflags=CREATE_NEW_CONSOLE)
sleep(10)
test.kill()
Try this
import os
os.system("taskkill /im make.exe")
cmd = 'kill -%d %d' % (signal.SIGINT, os.getpid())
subprocess.call(cmd.split())
This will kill the current processes
You can run another subprocess and kill by PID:
from subprocess import Popen, CREATE_NEW_CONSOLE
test=Popen(["cmd","/K","appium -p 4723"],creationflags=CREATE_NEW_CONSOLE)
pid = test.pid
sleep(10)
subprocess.Popen('taskkill /F /T /PID %i' % pid) # force kill and kill all child processes
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.