使用adb调用Python连续子进程

2024-04-29 10:05:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试制作一个python脚本,通过adb检查数据库的内容。问题是在我的代码中,只有第一个subprocess.call执行()并忽略其余部分。由于我对Python相当陌生,我不确定如何修复它。代码如下:

import subprocess

def root():
    subprocess.call('adb shell',shell=True)
    x=input('Enter package name: ')
    openSql(x)


def openSql(x):
    subprocess.call('cd data/data/%s/databases/'%(x),shell=True)
    table=input('Enter table name: ')
    openTable(table)

def openTable(table):
    subprocess.call('sqlite3 table',shell=True)
    subprocess.call('select * from %s'%(table),shell=True)

root()

它没有给出任何错误,但它只是在我的仿真器中输入根目录,其他什么都没有。在

^{pr2}$

Tags: 代码nametrueinputdatadeftableroot
2条回答
import subprocess

p=input('Enter package name: ')
d=input('Enter database name: ')
t=input('Enter table name: ')
print subprocess.check_output(["adb", "shell", "sqlite3 /data/data/{}/databases/{}.db 'select * from {};'".format(p, d, t)])

调用root函数root(),这会将您放入adb shell。您试图从adbshell运行一个python命令input,但该命令不起作用。在

有几个链接可以帮助您完成您想要的操作:

runpythonfromshell

sl4a

相关问题 更多 >