2016-07-20 5 views
-3

Wie führe ich diesen logcat-Befehl über Python aus?Erstellen einer neuen adb logcat Textdatei in einem Python-Skript

Ich habe dies versucht, aber es wird keine Datei im Ausgabeordner erstellt. Ich habe einen Workaround gemacht und es hat funktioniert.

Ich habe ein anderes Problem: Die Datei log1.txt ist ausgefüllt. Es wird erwartet, dass Zeilen mit dem Tag "sample" aus der log1.txt-Datei in eine andere neue Datei kopiert werden. Ich habe eine Funktion dafür geschrieben, aber nur eine Instanz der Tag-Zeile wird in der neuen Datei gedruckt, wo als Druckanweisung vor diesem 3 Zeilen in der Ausgabe gedruckt werden. Könnte jemand plz helfen.

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

Sie haben versucht, "das" und "this" ist ??? – Julien

+0

cmd = "adb logcat -d> ~/log1.txt" time.sleep (10) prozess = subprozess.Popen (cmd, stdout = subprozess.PIPE, shell = True) – sheetal

Antwort

0

Versuchen Sie, diese

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

danke ich habe versucht: – sheetal

+0

cmd = " adb logcat -d> ~/log1.txt " time.sleep (10) Prozess = Subprozess.Popen (cmd, stdout = subprocess.PIPE, Shell = True) – sheetal

+0

Wie kopieren Sie die Ausgabe in eine Datei" parsedlog. txt" – sheetal

Verwandte Themen