pure-python-adb icon indicating copy to clipboard operation
pure-python-adb copied to clipboard

How can I get shell() output in real time?

Open kernel-cyrus opened this issue 4 years ago • 2 comments

kernel-cyrus avatar Apr 28 '21 09:04 kernel-cyrus

Not sure if you need something like this still but though I would share this with ye as I was looking for quite sometime on a 'how to' and managed to get a live log from the device.

device.shell("logcat", handler=dump_logcat)
def dump_logcat(connection):
    while True:
        data = connection.read(1024)
        if not data:
            break
        print(data.decode('utf-8'))

    connection.close()

gitagogaming avatar Feb 24 '22 06:02 gitagogaming

Not sure if you need something like this still but though I would share this with ye as I was looking for quite sometime on a 'how to' and managed to get a live log from the device.

device.shell("logcat", handler=dump_logcat)
def dump_logcat(connection):
    while True:
        data = connection.read(1024)
        if not data:
            break
        print(data.decode('utf-8'))

    connection.close()

I was facing issue while using your example, it seems that dump_logcat function should be declared before using it. below program worked for me.

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)

dmdhrumilmistry avatar Aug 07 '22 09:08 dmdhrumilmistry