I am executing ADB commands through Python and it works fine till some extent. The code is :
#!/usr/bin/python
import sys
import string
import os
import subprocess
cmd = 'adb shell ls'
s = subprocess.Popen(cmd.split())
print "Again"
t = str(s)
for me in t.split('\n') :
print "Something"
print me[1]
The output i get is :
static-243:Scripts adityagupta$ ./hellome.py
Again
Something
s
static-243:Scripts adityagupta$ config
cache
sdcard
acct
mnt
vendor
d
etc
ueventd.rc
ueventd.goldfish.rc
system
sys
sbin
proc
init.rc
init.goldfish.rc
init
default.prop
data
root
dev
Any suggestion i could make each a list and store each element in it. The list should look like
list = [cache, sdcard, acct, mnt, vendor ..] and so on.
Shouldn't you use the check_output convenience function?
#!/usr/bin/env python
import subprocess
cmd = 'adb shell ls'
s = subprocess.check_output(cmd.split())
print s.split('\r\n')
It works just fine here (Ubuntu box). Note that the newline separators are '\r\n' instead of just '\n'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With