使用adb的Python连续子进程调用 [英] Python consecutive subprocess calls with adb

查看:133
本文介绍了使用adb的Python连续子进程调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个python脚本来通过adb检查数据库的内容。关键是在我的代码中,仅执行第一个subprocess.call(),其余的都被忽略。由于我是Python的新手,所以我不确定如何修复它。这是代码:

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

它给出没错,但是它只是在我的仿真器中进入了root用户。

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

root@android:/ # 


推荐答案

您称 root 函数 root(),将您带到adb shell中。您正在尝试从adb shell运行 python 输入 input 的命令,该命令将不起作用。

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

这篇关于使用adb的Python连续子进程调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆