results = subprocess.Popen("adb devices", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines()
for line in results:
print line
importsubprocesslogcat=subprocess.Popen(["adb","logcat"],stdout=subprocess.PIPE)whilenotlogcat.poll():line=logcat.stdout.readline()ifline:print(line)# your logic
else:breakprint("Return code",logcat.returncode)logcat.kill()# kill logcat process if needed