File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- #!/usr/bin/env python
21# -*- coding: utf-8 -*-
32
43'''
87'''
98
109import 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
2014def 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
2528if __name__ == "__main__" :
26- if utils .system is "Windows" :
27- win ()
28- else :
29- linux ()
29+ win ()
You can’t perform that action at this time.
0 commit comments