用subprocess执行adb shell命令怎么终止

问题:
在程序中使用 adb shell top 命令获取 数据时,程序一直运行无法停止
原命令:
subprocess.run(f'adb shell COLUMNS=200 top -d 2 | grep "com.xxx.xxx" > 123.txt', shell=True)
 
解决思路:
 
logger.info("开始收集cpu_memory数据")
logcmd = f'adb shell COLUMNS=200 top -d 2 | grep {package_name}'
logfile = open(cpu_memory_log_path, "w")
process = subprocess.Popen(logcmd, stdout=logfile, shell=True, stderr=subprocess.PIPE)
time.sleep(10)
process.terminate()

posted on 2021-12-02 21:41  阿虾  阅读(592)  评论(0编辑  收藏  举报

导航