如何在设置ADB_TRACE=adb时在cmd中获取信息
我试着在把文件推送到设备时获取进度。
当我在命令行中输入“set ADB_TRACE=adb”时,它是可以工作的(我在这个页面上找到的)。
然后我想在 Python 2.7 中使用这个功能。
cmd = "adb push file /mnt/sdcard/file"
os.putenv('ADB_TRACE', 'adb')
os.popen(cmd)
print cmd.read()
但是它什么都不显示。
我该怎么才能获取这些详细信息呢?
操作系统:win7
1 个回答
1
os.popen
这个功能已经不再推荐使用了:
从版本 2.6 开始:这个功能已经过时了。建议使用
subprocess
模块。特别要查看用subprocess
模块替换旧功能的部分。
请使用 subprocess
代替:
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