Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
162 views
in Technique[技术] by (71.8m points)

android - Python consecutive subprocess calls with adb

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:/ # 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...