【问题标题】:Python can not capture full adb logsPython 无法捕获完整的 adb 日志
【发布时间】:2014-11-18 18:27:57
【问题描述】:

我想要实现的 - 运行 adb log(日志正在运行), 在android上做一些活动, 停止/结束日志捕获 (ctrl+c), 日志的后处理。

我面临的唯一问题 - 无法在文件中捕获完整的 logcat 日志

import sys 
import subprocess
import time
import ctypes

# start

print "test start"
time.sleep(5)

# log capturing start, log does not stop it will keep on running
proc = subprocess.Popen("adb logcat -v time",stdout=subprocess.PIPE )
time.sleep(3) # just so it runs for a while


print "calc start"
time.sleep(5)
#START test************************************

Some code for testing



#CTRL C*************************************************

try:
    ctypes.windll.kernel32.GenerateConsoleCtrlEvent(0, 0)
    proc.wait()
except KeyboardInterrupt:
    print "ignoring ctrlc"
print "still running"


#********************adb log saving******************

text = proc.stdout.read()

f = open('C:\Python27\out_logs_dd\log.txt', 'w')

f.write(text)

with open('C:\Python27\out_logs_dd\log.txt', 'w') as f:
   f.write(text)

f.close()

当我运行这段代码时,一切都在运行,但日志大小太小了。 我搜索并知道"proc.communicate()"可能是解决方案。 我试过'communicate',但无法解决问题。 任何帮助指针请。

【问题讨论】:

    标签: android python logging adb


    【解决方案1】:

    proc.stdout.readline() 替换proc.stdout.read() 为我解决了这个问题。 stdout.read() 读取所有内容,直到 EOF - 大大降低速度。类似问题:Communicate with subprocess without waiting for the subprocess to terminate on windows

    【讨论】:

      【解决方案2】:

      你可以使用adb shell logcat代替abd logcat in

      proc = subprocess.Popen("adb shell logcat -v time",stdout=subprocess.PIPE)

      它将提供所有日志。

      我希望它会起作用。

      【讨论】:

      • Dreamcoder,我已经尝试过“adb shell logcat”,它不提供完整的日志。
      猜你喜欢
      • 1970-01-01
      • 2021-08-16
      • 1970-01-01
      • 2012-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多