当我设置ADB_TRACE = adb时,如何获取cmd中的信息 [英] How can I get the info in cmd when I set ADB_TRACE=adb

查看:1279
本文介绍了当我设置ADB_TRACE = adb时,如何获取cmd中的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试获取将文件推送到设备时的进度。
当我在cmd中设置ADB_TRACE = adb时可用(在此页面



然后我想在python 2.7中使用它。

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


如何获取这些详细信息?



操作系统:win7

解决方案>

os .popen 已弃用:


自2.6版后弃用:此函数已过时。使用
子进程模块。特别是用
子进程模块部分检查替换旧的函数。


使用 子过程 代替:

  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()

如果mysp.returncode!= 0:
print stderr
else:
print stdout


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

解决方案

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

这篇关于当我设置ADB_TRACE = adb时,如何获取cmd中的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆