【发布时间】: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