import subprocess
import select
f = subprocess.Popen(['adb', 'shell', 'logcat'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = select.poll()
p.register(f.stdout)
while True:
if p.poll(1):
logMsg = f.stdout.readline().decode()
if "Successful install of" in logMsg:
print('raw log cat message\n'+logMsg)
print('-----------------------------------')
packageName = logMsg.split('of ')[1].split(' ')[0];
print('packageName: '+packageName)
subp = subprocess.Popen(("adb shell pm path '"+packageName+"' | cut -f 2 -d ':'").split(), stdout=subprocess.PIPE)
originalPath = subp.stdout.readline().decode()
subp.kill()
targetPath = '/Users/user/apkPull/'+packageName+'.apk'
print(originalPath)
print(targetPath)
cmd = "adb " + "pull " + originalPath + " " + targetPath
subp = subprocess.run(cmd.split())
Python을 이용하여 android logcat을 통한 로그를 실시간 감시하여 apk 를 특정 localPath로 복사하는 코드