52524

Python consecutive subprocess calls with adb

Question:

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:/ #

Answer1:

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:

<a href="http://code.google.com/p/python-for-android/wiki/RunPythonFromShell" rel="nofollow">runpythonfromshell</a>

<a href="http://code.google.com/p/android-scripting/wiki/UserGuide" rel="nofollow">sl4a</a>

Answer2:

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

Recommend

  • Stream a parameter to T-SQL SP from C#?
  • python subprocess use cmd for print() commands
  • Get return value from shell command in python
  • How do I use substring in OpenSQL ABAP WHERE clause?
  • AWS: Lambda function cannot call rest api using private API of EC2 instance
  • How can I communicate between two python scripts?
  • why calling cd shell command through system() or execvp() from a child process won't work?
  • Installing Perl6 and Panda on Ubuntu 15.10. Problems with bootstrap.pl
  • How can I get the full list of running processes on a Mac from a python app
  • Read text file that is not in the main package in a runnable jar
  • Roxygen error “Skipping invalid path”
  • JBoss External Properties Files in Classpath
  • How to handle images sent by a mobile device?
  • htaccess add www if not subdomain, if subdomain remove www
  • java inputstream
  • chrome.tabs.executeScript only fires when the Developer Console is open
  • How to render a blob on a canvas element?
  • Spark fat jar to run multiple versions on YARN
  • How to use an array of arrays with array_map(…) in PHP?
  • FFmpeg Conversion Error
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • Jenkins: How To Build multiple projects from a TFS repository?
  • Bug in WPF DataGrid
  • How to add date and time under each post in guestbook in google app engine
  • TFS: Get latest causes slow project reloading
  • Javascript Callbacks with Object constructor
  • JSON with duplicate key names losing information when parsed
  • what is the difference between the asp.net mvc application and asp.net web application
  • How to make Safari send if-modified-since header?
  • Why winpcap requires both .lib and .dll to run?
  • Return words with double consecutive letters
  • Matrix multiplication with MKL
  • Python: how to group similar lists together in a list of lists?
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Binding checkboxes to object values in AngularJs
  • How can i traverse a binary tree from right to left in java?
  • How can I use `wmic` in a Windows PE script?