Execute commands via device.shell(). For streaming output like logcat, provide a handler function.
Basic shell command
device.shell("echo hello world !")
Streaming logcat with a handler
def dump_logcat(connection):
while True:
data = connection.read(1024)
if not data:
break
print(data.decode('utf-8'))
connection.close()
device.shell("logcat", handler=dump_logcat)
Reading logcat line by line
def dump_logcat_by_line(connect):
file_obj = connect.socket.makefile()
for index in range(0, 10):
print("Line {}: {}".format(index, file_obj.readline().strip()))
file_obj.close()
connect.close()
device.shell("logcat", handler=dump_logcat_by_line)