i'm creating python script work fastboot commands, , trying
fastboot getvar product in order see product have selected. problem when run code:
p = subprocess.popen(['fastboot', "getvar", "all"]) out, err = p.communicate() print "we got: " + out out empty. works fine if pass in devices instead of getvar all.
i think has stack overflow question i'm having hard time translating python:
how can output getvar in string, instead of outputted terminal?
edit:
i found github account of made similiar function adb, , modified achieve want:
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 the problem uses old os.popen method. new question same, how do subprocess?
for fastboot getvar all need capture stderr instead of stdout:
print subprocess.check_output(['fastboot', 'getvar', 'all'], stderr=subprocess.stdout)
Comments
Post a Comment