用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()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM