How can I get the info in cmd when I set ADB_TRACE=adb

折月煮酒 提交于 2019-12-11 13:21:55

问题


I tried to get the progress when pushing a file to device. It works when I "set ADB_TRACE=adb" in cmd (found in this page)

Then I want to use it in python 2.7.

cmd = "adb push file /mnt/sdcard/file"
os.putenv('ADB_TRACE', 'adb')
os.popen(cmd)
print cmd.read()

It shows nothing. How can I get these details?

OS:win7


回答1:


os.popen is deprecated:

Deprecated since version 2.6: This function is obsolete. Use the subprocess module. Check especially the Replacing Older Functions with the subprocess Module section.

Use subprocess instead:

import subprocess as sp

cmd = ["adb","push","file","/mnt/sdcard/file"]
mysp = sp.popen(cmd, env={'ADB_TRACE':'adb'}, stdout=sp.PIPE, stderr=sp.PIPE)
stdout,stderr = mysp.communicate()

if mysp.returncode != 0:
    print stderr
else:
    print stdout


来源:https://stackoverflow.com/questions/14779146/how-can-i-get-the-info-in-cmd-when-i-set-adb-trace-adb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!