2016-07-20 42 views
-3

如何通過python執行這個logcat命令?在python腳本中創建一個新的adb logcat文本文件

adb logcat -d > log1.txt 

我試過這個,但是在輸出文件夾中沒有創建文件。 我做了一個解決方法,它的工作。

我有另一個問題:填充log1.txt文件。我希望將標記爲「sample」的行從log1.txt文件複製到另一個新文件。我爲此編寫了一個函數,但只有一個標記行實例正在打印到新文件中,在此之前,打印語句在此輸出中輸出3行。有人可以幫忙嗎?

for line in open("log1.txt",'r'):   
    cmd="sample" 
    if cmd in line: 
     print line 
     f = open('myfile','w') 
     f.write(line) 
+0

你試過 「這個」 和 「這」 ??? – Julien

+0

cmd =「adb logcat -d>〜/ log1.txt」 time.sleep(10) process = subprocess.Popen(cmd,stdout = subprocess.PIPE,shell = True) – sheetal

回答

0

試試這個

with open('out-file.txt', 'w') as f: 
    subprocess.call(['adb','logcat', '-d'], stdout=f) 
+0

謝謝我試過了: – sheetal

+0

cmd =「 adb logcat -d>〜/ log1.txt「 time.sleep(10) process = subprocess.Popen(cmd,stdout = subprocess.PIPE,shell = True) – sheetal

+0

如何將輸出複製到文件」parsedlog「中。文本」 – sheetal

相關問題