python 控制adb

来源:互联网 发布:win7网络图标灰色 编辑:程序博客网 时间:2024/05/22 00:32

import os
os.system(“adb -s ‘192.168.0.113’ shell ps | grep org.yeshen.test | awk ‘{print$2}’ | wc -l”)

检查在线的设备

adb devices
import subprocess# 检查在线的设备online = set()cmd = "adb devices | grep '\tdevice' | cut -d ':' -f1"pipe = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)while True:    out = pipe.stdout.readline()    if not out and pipe.returncode is not None:        break    online.add(out.strip())    pipe.poll()pipe.stdout.close()print online

python控制 adb 管道

import subprocessip=192.168.0.110package="org.yeshen.test"cmd = "adb -s %s:5555 shell ps | grep %s | wc -l" % (ip, package)pipe = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)app_count = pipe.stdout.readline().strip()pipe.stdout.close()print "%s >count> %s" % (package,app_count)