我怎样才能在cmd中的信息时,我设置ADB_TRACE = ADB(How can I get th

2019-10-17 16:30发布

我试图推动一个文件设备时,为了获得进展。 它的工作原理,当我“设置ADB_TRACE = ADB”在cmd中(可在此页 )

然后我想在Python 2.7使用它。

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

这说明不了什么。 我怎样才能获得这些细节?

操作系统:WIN7

Answer 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


文章来源: How can I get the info in cmd when I set ADB_TRACE=adb