我正在通过 Python 执行 ADB 命令,它在某种程度上工作正常。 代码是:
#!/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]
我得到的输出是:
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
任何建议我都可以将每个列表制作成一个列表并将每个元素存储在其中。 该列表应如下所示
list = [cache, sdcard, acct, mnt, vendor ..] 等等。
最佳答案
你不应该使用 check_output
便捷函数吗?
#!/usr/bin/env python
import subprocess
cmd = 'adb shell ls'
s = subprocess.check_output(cmd.split())
print s.split('\r\n')
它在这里工作得很好(Ubuntu 框)。请注意,换行符是“\r\n”,而不仅仅是“\n”。
关于android - 通过 Python 执行 Android 命令并将结果存储在列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12025195/