首页 > 解决方案 > 如何运行 stop logcat 一段时间或检测某些关键字

问题描述

我希望编写一个脚本来完成某些工作。

我遇到的问题是logcat我的状况并没有停止。

logcat我的意图是在它运行一段时间后停止,或者计算机从日志中检测到一个关键短语。

  1. time.sleep()我尝试通过在命令下方放置 a 来使用时间限制方法,logcat但显然该过程logcat永远停留在它下面的任何代码都没有执行。所以我尝试-d time放入the adb shell logcat. 但是无论-d我输入什么值,它下面的代码都会立即执行。

  2. 另一种方法是在日志中出现某些短语时停止,logcat但我不知道该怎么做。

任何人都可以帮忙吗?

import os
import subprocess
import time

file_directory =r"D:\A.LXR\ns-test\record_SinglePointTV-45du_5m_45_Midea-NS_adult_normal_guan-bi-zuo-you-bai-feng_25_25.wav"
file_name ='in_2021-23-02_15-45-22.pcm.wav'

push_command = 'adb push '+file_directory
push_command = os.path.join(push_command,file_name)
push_command = push_command+' /sdcard/'+file_name


test_command = 'adb shell am broadcast -a start_feed --es path /sdcard/'+file_name



print('pushing audio')
subprocess.call(push_command)


subprocess.Popen('adb shell logcat -c')
print('recording the logs')
return_log = subprocess.call(r"adb shell logcat -d 50000 -f > D:\A.LXR\ns-test\record_SinglePointTV-45du_5m_45_Midea-NS_adult_normal_guan-bi-zuo-you-bai-feng_25_25.wav\in_2021-23-02_15-45-22.log", shell = True)


subprocess.call(test_command)
# time.sleep(5)

subprocess.Popen('adb shell killall -2 logcat')
print('stop recording logs')


print('extracting sliced audio')
subprocess.Popen(r'adb pull /sdcard/speech/* > D:\A.LXR\ns-test')
subprocess.Popen('adb shell rm -f -r /sdcard/speech/*')

谢谢

标签: pythonandroidshellsubprocess

解决方案


推荐阅读