2014-09-24 66 views
0

我想達到的目標 - 執行adb日誌(日誌正在運行), 做在Android上, 停止/結束日誌捕捉一些活動(Ctrl + C),日誌 後處理。Python不能拍攝全亞行日誌

只有我面臨的問題 - 不能拍攝全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',但無法解決問題。 任何幫助指針請。

回答

-1

可以使用ADB殼的logcat代替ABD的logcat的

proc等於subprocess.Popen( 「亞行外殼的logcat -v時間」,標準輸出= subprocess.PIPE)

它會給所有日誌。

我希望它能工作。

+0

Dreamcoder,我已經嘗試過「adb shell logcat」,它沒有提供完整的日誌。 – 2014-09-25 06:25:40