我就废话不多说了,直接上代码吧!
# -*- coding: UTF-8 -*-
import os
import re
port = 8080
def kill_process():
ret = os.popen("netstat -nao|findstr " + str(port))
#注意解码方式和cmd要相同,即为"gbk",否则输出乱码
str_list = ret.read().decode('gbk')
ret_list = re.split('',str_list)
try:
process_pid = list(ret
1