いくつかの fastboot コマンドで動作する python スクリプトを作成しています。
fastboot getvar product
選択した製品を確認するため。問題は、このコードを実行するときです。
p = subprocess.Popen(['fastboot', "getvar", "all"])
out, err = p.communicate()
print "We got: " + out
外は空です。getvar all の代わりにデバイスを渡せば問題なく動作します。
このスタックオーバーフローの質問と関係があると思いますが、Pythonに翻訳するのに苦労しています:
端末に出力するだけでなく、 getvar からの出力を文字列に戻すにはどうすればよいですか?
編集:
私は adb に似た機能を作った誰かの github アカウントを見つけ、私が望むものを達成するためにそれを修正しました:
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 メソッドを使用していることです。私の新しい質問は同じですが、サブプロセスでこれを行うにはどうすればよいですか?