2

In order to retrieve my Android app's database from device, I execute this commands:

prompt1> adb shell
prompt2> run-as my.app.package
prompt3> chmod -R 777 databases
prompt3> exit
prompt2> cat /data/data/my.app.package/databases/database.db > /sdcard/database.db
prompt2> exit
prompt1> adb pull /sdcard/database.db

I want automate this process so I have created a script with those commands. Problem is that when I execute it, adb shell is opened and the next commands are not executed.

Note that run-as my.app.package opens another third shell.

EDIT

When I execute the script:

prompt1> get_database.cmd
prompt2> _

It opens prompt2, but it stops.

How can I do it?

5
  • Actually, run-as open a third shell Commented Dec 21, 2015 at 15:36
  • Your examples are somewhat confusing. Are you searching for a solution in a UNIX-like shell (say sh, csh, etc.) or for Windows' CMD? Commented Dec 22, 2015 at 10:04
  • Sorry, my fault. I need a CMD solution. Commented Dec 22, 2015 at 10:05
  • Then I would suggest, you rework your question (examples). The first one sports a whole slew of UNIXish commands (cat, chmod, etc.) can lead to the impression that you're actually looking for sh. Commented Dec 22, 2015 at 10:08
  • I have them installed in my Windows machine. Commented Dec 22, 2015 at 10:15

2 Answers 2

1

You can try passing the commands to the shell with quotes:

adb shell "
adb run-as my.app.package 'chmod -R 777 databases; exit'
cat /data/data/my.app.package/databases/database.db > /sdcard/database.db
exit
"
adb pull /sdcard/database.db
Sign up to request clarification or add additional context in comments.

1 Comment

Can you add some details? The single quote '...' can be replaced by an external file adb run-as my.app.package < script.adb with chmod -R 777 databases; exit inside script.adb
0

Finally, I have solved it this way:

@echo off
IF "%1" == "" goto USAGE
IF "%2" == "" goto USAGE

adb shell "run-as %1 chmod -R 777 /data/data/%1/databases; cat /data/data/%1/databases/%2 > /sdcard/%2"
adb pull /sdcard/%2
goto END

:USAGE
@echo Usage: %0  ^<package^> ^<file_name^>

:END

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.