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

2019-07-28 06:58发布

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条回答
Evening l夕情丶
2楼-- · 2019-07-28 07:20

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
查看更多
登录 后发表回答