zoukankan      html  css  js  c++  java
  • python进入adb shell交互模式

    import subprocess
    
    #方法一:进入某个环境执行语句(adb shell),注意shell内部命令需要带
    ,执行完后一定记得执行exit命令退出,否则会阻塞
    obj = subprocess.Popen(['adb', 'shell'], shell = True, stdin=subprocess.PIPE, stdout=subprocess.PIPE ,stderr=subprocess.PIPE)
    obj.stdin.write('ls
    '.encode('utf-8'))
    obj.stdin.write('exit
    '.encode('utf-8'))  #重点,一定要执行exit
    info,err = obj.communicate()
    print(info.decode('gbk'))
    print(err.decode('gbk'))
    
    #方法二:进入某个环境执行语句(adb shell),命令用列表方式全部列出
    cmds = [
        "cd data",
        'cd data',
        "ls",
        "exit",#这是是非常关键的,退出
    ]
    obj = subprocess.Popen("adb shell", shell= True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    info = obj.communicate(("
    ".join(cmds) + "
    ").encode('utf-8'));
    for item in info:
        if item:
            print(item.decode('gbk'))
    

      

    多思考也是一种努力,做出正确的分析和选择,因为我们的时间和精力都有限,所以把时间花在更有价值的地方。
  • 相关阅读:
    金融理财
    股权穿透图资料总结
    v-cloak指令用法
    前端跨域解决方案
    better-scroll
    vant-list实现下拉加载更多
    webpack原理
    .NET Framwork WebApi 添加swagger 在线接口文档步骤
    CORE API 限流,防止,链接数过多而崩溃。
    VS2019推送代码到GIT仓库
  • 原文地址:https://www.cnblogs.com/LiuXinyu12378/p/12519280.html
Copyright © 2011-2022 走看看