python calls adb shell

Table of contents

Python calls bat to start a new window, but it cannot automatically perform pre-set operations after entering the shell.

Python starts a new cmd window, but it cannot automatically perform pre-set operations after entering the shell.


Python calls bat to start a new window, but it cannot automatically perform pre-set operations after entering the shell.

   bat_file_path = 'adb_call.bat'
    with open(bat_file_path, 'w') as file:
        file.write(f'adb -s {ip} shell\n')

        # file.write(f'tail -fn 200 /sdcard/aaa.txt\n')


    # call_adb(push_str,if_pring=True)
    print('push end')
    subprocess.Popen(['cmd', '/c', 'start', 'cmd', '/k', bat_file_path])

Python starts a new cmd window, but it cannot automatically perform pre-set operations after entering the shell.

def look_log(ip):
    log_path=f"/sdcard/sandstar/app/{log_name}"
    adb_str = f"adb connect {ip}"
    # fn='-f'
    fn='-fn 200'
    res = call_adb(adb_str)

    command =f'adb -s {ip} shell tail -fn 200 /sdcard/2023-09-16.txt'
    # command =f'adb -s {ip} shell'
    subprocess.run(['cmd', '/c', 'start', 'cmd', '/k', command])

Guess you like

Origin blog.csdn.net/jacke121/article/details/132940152