android - Capture output from adb logcat -


i automating android application , need able capture logs while running automation tests. have tried using terminal emulator seems give console logs. next tried using

        log = subprocess.check_output(["adb", "logcat"]) 

but when automation script stops indefinitely (presumably because waiting continue after logcat capture complete), not work me because need logcat run in background, while script running. maybe 'popen' way go, , pipe output? thank you!

the logs "running in background", it's whether you're looking @ them. suggest instead, when need log dump, using

adb logcat -d 

which dump has, exit.

so @ start of test run:

subprocess.call(shlex.split('adb logcat -c')) 

to clear logs.

so @ end (and before restart), dump logs:

log = subprocess.check_output(shlex.split('adb logcat -d')) open("loggy.file", "w") f:     f.write(log) 

Comments