一键结束port 5037占用

输入cmd进入dos界面,进入android-sdk-windows\platform-tools目录,执行下面命令
启动adb start-server
出现下面错误
* daemon not running. starting it now on port 5037 *
ADB server didn't ACK
* failed to start daemon *

运行下面脚本,一键结束相关进程

# -*- coding: utf-8-*-

import subprocess

p=subprocess.Popen("netstat -ano",stdout=subprocess.PIPE)

stdoutdata,stderrdata=p.communicate('')

ss=stdoutdata.split("\r\n")

for s in ss:

    if(not s):

        continue;

    #print s;

    if s.find("127.0.0.1:5037") >0 and s.find("LISTENING")>0:

        pid=s[s.rindex(" ")+1:];

        subprocess.Popen("taskkill /F /T /PID "+str(pid),shell=True);

        break;

 

你可能感兴趣的:(port)