我正在创建一个python脚本来使用一些快速启动命令,并且我正在尝试这样做
fastboot getvar product为了看看我选的是什么产品。问题是当我运行这段代码时:
p = subprocess.Popen(['fastboot', "getvar", "all"])
out, err = p.communicate()
print "We got: " + outOut是空的。如果我传入的是设备而不是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方法。所以我的新问题是一样的,但是我如何用子过程来做到这一点?
发布于 2013-07-20 03:48:43
对于fastboot getvar all,您需要捕获stderr而不是stdout
print subprocess.check_output(['fastboot', 'getvar', 'all'], stderr=subprocess.STDOUT)https://stackoverflow.com/questions/17748473
复制相似问题