2

I'm trying to automate the process of pulling the database from my app and then pushing an altered version back to the device, but it's not working as expected.

Following Pilot_51's answer on this topic Android ADB access to application databases without root I was able to extract the database running the commands manually. But when I put them on a .bat file, every Unix command executed returns a "not found" kind of error.

Here's the error I get:

run-as: exec failed for chmod 666 ./database/mydatabase.db; exit Error:No such file or directory

And here's the .bat script code:

@echo off

:Ask
echo (A) Pull or (B) Push

set INPUT=
set /P INPUT=Input choice: %=%

If /I "%INPUT%"=="a" goto A 
If /I "%INPUT%"=="b" goto B
echo Wrong choice & goto Ask

:A
adb shell "run-as com.example.myapp 'chmod 666 ./databases/mydatabase.db; exit'; exit"
adb pull /data/data/com.example.myapp/databases/mydatabase.db C:/
goto End

:B
adb push C:/mydatabase.db /data/data/com.example.myapp/databases/mydatabase.db
adb shell "run-as com.example.myapp 'chmod 660 ./databases/mydatabase.db; exit'; exit"

:End
pause

If I try running adb shell with "run-as com.example.myapp 'ls'" only, it does displays the folders. Why is ls working, but chmod doesn't get recognized?

Community
  • 1
  • 1
fehbari
  • 1,429
  • 2
  • 16
  • 22
  • Note also that @Alex's solution requires each command to be sent in "run-as". i.e. you can't send more than one command at a time. Multiple commands can't be sent by enclosing them in 'single quotes' – Richard Le Mesurier Feb 06 '14 at 09:18

1 Answers1

6

You need neither single quotes nor exit comands. Just do:

adb shell "run-as com.example.myapp chmod 666 databases/mydatabase.db"
Alex P.
  • 30,437
  • 17
  • 118
  • 169