Python subprocess 使用(一)
Python subprocess 使用(一)
本文主要讲下 subprocess 的简单使用.
1: 通过subprocess 获取设备信息
import subprocess
def get_android_device_info():
# 使用adb命令获取设备信息
result = subprocess.run(['adb', 'devices', '-l'], capture_output=True, text=True)
output = result.stdout.strip()
# 解析设备信息
devices = []
lines = output.split('\n')
for line in lines[1:]:
if 'device' in line:
device_info = line.split()
device = {
'serial': device_info[0],
'model': device_info[4],
'device': device_info[5],
'product': device_info[3],
'transport_id': device_info[6]
}
devices.append(device)
return devices
# 调用函数获取设备信息
devices = get_android_device_info()
for device in devices:
print('Serial:', device['serial'])
print('Model:', device['model'])
print('Device:', device['device'])
print('Product:', device['product'])
print('Transport ID:', device['transport_id'])
print('--')
具体的adb 执行结果如下:
List of devices attached
6b4a96b2 device usb:1-1 product:LeMax2_WW model:LEX820 device:le_x2 transport_id:43
2: 通过subprocess 获取屏幕分辨率
def get_device_physical():
command = 'adb shell wm size'
result = subprocess.check_output(command.split()).decode().strip()
resolution = result.split()[-1]
return resolution
print('设备分辨率:' + str(get_device_physical()))
3: 获取设备系统日志
def capture_android_log():
# 使用adb命令获取Android系统日志
command = "adb logcat"
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# 读取日志输出
while True:
line = process.stdout.readline().decode("utf-8")
if line:
print(line.strip())
else:
break
# 调用函数抓取Android系统日志
capture_android_log()
Python subprocess 使用(一)的更多相关文章
- 【python库模块】Python subprocess模块功能与常见用法实例详解
前言 这篇文章主要介绍了Python subprocess模块功能与常见用法,结合实例形式详细分析了subprocess模块功能.常用函数相关使用技巧. 参考 1. Python subprocess ...
- python subprocess popen 静默模式(不弹出console控制台)
python subprocess popen 静默模式(不弹出console控制台) import subprocess,sys IS_WIN32 = 'win32' in str(sys.plat ...
- python subprocess相关操作
python subprocess常用操作 1.subprocess模块的常用函数 函数 描述 subprocess.run() Python 3.5中新增的函数.执行指定的命令,等待命令执行完成后返 ...
- Python subprocess.Popen communicate() 和wait()使用上的区别
之所以会纠结到这个问题上是因为发现在调用Popen的wait方法之后程序一直没有返回.google发现wait是有可能产生死锁的.为了把这个问题彻底弄清楚,搜索一些资料过来看看: 原文链接:http: ...
- python subprocess阻塞
import select import os import subprocess import time import fcntl args = ['python','./fetch_file2.p ...
- python subprocess 自动运行实验室程序
import threading, os, subprocess, time exec_path = "/home/xhz/gems/ruby/amd...../bin/tester.exe ...
- Python subprocess模块学习总结
从Python 2.4开始,Python引入subprocess模块来管理子进程,以取代一些旧模块的方法:如 os.system.os.spawn*.os.popen*.popen2.*.comman ...
- python subprocess重定向标准输出
subprocess.call("ping -c 1 %s" % ip,shell = True,stdout = open('/dev/null','w'),stderr = s ...
- Working with Python subprocess - Shells, Processes, Streams, Pipes, Redirects
Posted: 2009-04-28 15:20 Tags: Python Note Much of the "What Happens When you Execute a Command ...
- 【转】 Python subprocess模块学习总结
从Python 2.4开始,Python引入subprocess模块来管理子进程,以取代一些旧模块的方法:如 os.system.os.spawn*.os.popen*.popen2.*.comman ...
随机推荐
- 通过提示大语言模型进行个性化推荐LLM-Rec: Personalized Recommendation via Prompting Large Language Models
论文原文地址:https://arxiv.org/abs/2307.15780 本文提出了一种提示LLM并使用其生成的内容增强推荐系统的输入的方法,提高了个性化推荐的效果. LLM-Rec Promp ...
- ES13 中11个令人惊叹的 JavaScript 新特性
前言 与许多其他编程语言一样,JavaScript 也在不断发展.每年,该语言都会通过新功能变得更加强大,使开发人员能够编写更具表现力和简洁的代码. 小编今天就为大家介绍ES13中添加的最新功能,并查 ...
- 对称加密 vs 非对称加密
计算机网络在给我们带来便利的同时,也存在很多安全隐患,比如信息伪造,病毒入侵,端点监听,SQL 注入等,给我们日常生活造成很严重的影响. 那么这篇文章我就跟大家聊聊常见的网络安全隐患,只作为科普,不能 ...
- Ds100p -「数据结构百题」31~40
31.P2163 [SHOI2007]园丁的烦恼] 很久很久以前,在遥远的大陆上有一个美丽的国家.统治着这个美丽国家的国王是一个园艺爱好者,在他的皇家花园里种植着各种奇花异草. 有一天国王漫步在花园里 ...
- 删除软件 geek
下载链接 Geek Uninstaller_v1.5.1.162 -技术松鼠 (jishusongshu.com)
- RabbitMQ——RabbitMQ面试题
文章目录 为什么使用MQ?MQ的优点 消息队列有什么优缺点?RabbitMQ有什么优缺点? 你们公司生产环境用的是什么消息中间件? Kafka.ActiveMQ.RabbitMQ.RocketMQ 有 ...
- DPDK-22.11.2 [四] Virtio_user as Exception Path
因为dpdk是把网卡操作全部拿到用户层,与原生系统驱动不再兼容,所以被dpdk接管的网卡从系统层面(ip a/ifconfig)无法看到,同样数据也不再经过系统内核. 如果想把数据再发送到系统,就要用 ...
- go 流程控制之switch 语句介绍
go 流程控制之switch 语句介绍 目录 go 流程控制之switch 语句介绍 一.switch语句介绍 1.1 认识 switch 语句 1.2 基本语法 二.Go语言switch语句中cas ...
- 数据结构与算法 | 数组(Array)
数组(Array) 数组(Array)应该是最基础的数据结构之一,它由相同类型的元素组成的集合,并按照一定的顺序存储在内存中.每个元素都有一个唯一的索引,可以用于访问该元素. // java 数组示例 ...
- Educational Codeforces Round 148 [Rated for Div. 2]A~C
A #include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 60; char c ...