1

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

Community
  • 1
  • 1
tastypear
  • 25
  • 5

1 Answers1

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
mechanical_meat
  • 163,903
  • 24
  • 228
  • 223
  • thanks, i got the details, but the command does't work find.I got some "could not create socket" errors – tastypear Feb 08 '13 at 19:33
  • You're most welcome. Since you have the Python side taken care of, you might consider creating another question asking about the errors coming from `adb` command. – mechanical_meat Feb 08 '13 at 19:52