Python consecutive subprocess calls with adb

2019-09-19 22:10发布

I am trying to make a python script to check the contents of a database via adb. The thing is that in my code,only the first subprocess.call() is executed and the rest are ignored. Since i am fairly new to Python, i am not sure how to fix it. This is the code:

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

It gives no error but it just enters root at my emulator and nothing else.

root@android:/ # 

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-09-19 22:56
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)])
查看更多
闹够了就滚
3楼-- · 2019-09-19 22:58

You call the root function root(), which drops you into the adb shell. You are trying to run a python command input from the adb shell which will not work.

A couple of links to help do what you want:

runpythonfromshell

sl4a

查看更多
登录 后发表回答