Skip to content

Commit 85e9d75

Browse files
committed
modified kill_5037.py
1 parent 2b2ae71 commit 85e9d75

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

python/kill_5037.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# -*- coding: utf-8 -*-
32

43
'''
@@ -8,22 +7,23 @@
87
'''
98

109
import os
10+
import platform
1111

12-
from scriptUtils import utils
13-
14-
#5037端口占用时杀掉占用该端口的进程
15-
16-
def linux():
17-
pid = os.popen("netstat -anop | grep 5037 | grep LISTEN").read().split()[6].split("/")[0]
18-
os.system("kill %s" %pid)
12+
#5037端口占用时,打开该进程路径,且杀掉占用该端口的进程(只支持Windows)
1913

2014
def win():
2115
pid = os.popen("netstat -ano | findstr 5037 | findstr LISTENING").read().split()[-1]
16+
process_name = os.popen('tasklist /FI "PID eq %s"' %pid).read().split()[-6]
17+
process_path = os.popen('wmic process where name="%s" get executablepath' %process_name).read().split()[-1]
18+
#分割路径,得到进程所在文件夹名
19+
name_list = process_path.split("\\")
20+
del name_list[-1]
21+
directory = "\\".join(name_list)
22+
#打开进程所在文件夹
23+
os.system("explorer.exe %s" %directory)
24+
#杀死该进程
2225
os.system("taskkill /F /PID %s" %pid)
2326

2427

2528
if __name__ == "__main__":
26-
if utils.system is "Windows":
27-
win()
28-
else:
29-
linux()
29+
win()

0 commit comments

Comments
 (0)