Python和Android Fastb的输出

2024-06-13 12:14:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建一个python脚本来处理一些fastboot命令,我正在尝试这样做

fastboot getvar product

为了看看我选择了什么产品。问题是当我运行以下代码时:

^{pr2}$

外面是空的。如果我传入devices而不是getvar all,就可以正常工作。在

我认为这与堆栈溢出问题有关,但我很难将其转换为python:

fastboot getvar from batch file

如何将getvar的输出返回到字符串中,而不是直接输出到终端?在

编辑:

我找到了一个github账户,上面有人为adb做了一个类似的功能,并对其进行了修改,以达到我想要的效果:

def callFastboot(self, command):
    command_result = ''
    command_text = 'fastboot %s' % command
    results = os.popen(command_text, "r")
    while 1:
        line = results.readline()
        if not line: break
        command_result += line
    return command_result

out = test.callFastboot("getvar product 2>&1")
print "We got: " + out

问题是这使用的是旧的os.popen公司方法。所以我的新问题是相同的,但是如何使用子流程来实现这一点呢?在


Tags: text命令脚本产品oslineresultproduct