fehbari
fehbari

Reputation: 1449

ADB shell "run-as" from a .bat file not finding Unix commands

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?

Upvotes: 2

Views: 4897

Answers (1)

Alex P.
Alex P.

Reputation: 31686

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

adb shell "run-as com.example.myapp chmod 666 databases/mydatabase.db"

Upvotes: 6

Related Questions