python代码解决如何连续执行adb shell命令

例子1:

import subprocess 
cmdlist = []
        su = 'su'
        echo = 'echo "--update_package=/data/ota_package/{0}" >/cache/recovery/command'.format(otazip)
        exit1 = 'exit'
        exit2 = 'exit'
        cmdlist.append(su)
        cmdlist.append(echo)
        cmdlist.append(exit1)
        cmdlist.append(exit2)
        print(cmdlist)

        pro = subprocess.Popen('adb -s {0} shell'.format(udid), shell=True, stdin=subprocess.PIPE,
                               stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        st = pro.communicate(('\n'.join(cmdlist) + '\n').encode('utf-8'))

        os.system('adb -s {0} reboot recovery'.format(udid))
        time.sleep(600)

例子2:

import subprocess
def get_mcu_version(deviceid):
    nucleolusinfoadb = []
    su = 'su'
    mcujlink = 'getprop | grep mcurom'
    nucleolusinfoadb.append(su)
    nucleolusinfoadb.append(mcujlink)
    pro = subprocess.Popen('adb -s {0} shell'.format(deviceid), shell=True, stdin=subprocess.PIPE,
                           stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    st = pro.communicate(('\n'.join(nucleolusinfoadb) + '\n').encode('utf-8'))
    st1 = st[0].decode('utf-8')
    return st1.split(' ')[1][1:-3]

 

posted @ 2020-08-11 11:35  勇敢面对difficult  阅读(1307)  评论(0)    收藏  举报