方法一:
# -*- coding:utf-8 -*-
import os
from subprocess import Popen, PIPE, STDOUT
if __name__ == '__main__':
p = Popen(['tasklist'],stdout=PIPE, stderr=PIPE)
process_lists = str(p.stdout.read())
if 'chrome.exe' in process_lists:
Popen('taskkill /F /IM chrome.exe /T')
注意:输出流的类型是bytes还是str。
方法二:
# -*- coding:utf-8 -*-
import os
if __name__ == '__main__':
try:
os.system('taskkill /F /IM chrome.exe')
except:
print('not kill sucess')