This question already has answers here:
Read binary stdout data like screencap data from adb shell?
(19 answers)
Closed 5 years ago.
I tried the one liner solution to capture screenshot via adb and the file is created successfully on PC but it is unreadable:
C:\Program Files\Android\android-sdk\platform-tools>adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > c:\users\utilisateur\desktop\android_screenshot1.png
The file seem to be correct but I think the Magic is not correct:
EDIT: The same issue happened with Git Bash for Windows.
adb exec-out screencap -p > screen.png
will save it on your machine directly
#Passella answer worked for me with a little tweaking:
adb shell screencap -p "/mnt/sdcard/output.png" && adb pull "/mnt/sdcard/output.png" "C:\output.png" && adb shell rm "/mnt/sdcard/output.png"
I had to quote the paths and replace | with &&.
Also, if you are using a Genymotion simulator, it's better to use its own adb:
C:\"Program Files"\Genymobile\Genymotion\tools\adb shell screencap -p "/mnt/sdcard/output.png" && C:\"Program Files"\Genymobile\Genymotion\tools\adb pull "/mnt/sdcard/output.png" "C:\output.png" && C:\"Program Files"\Genymobile\Genymotion\tools\adb shell rm "/mnt/sdcard/output.png"
Try this:
adb shell screencap -p /mnt/sdcard/output.png | adb pull /mnt/sdcard/output.png C:\output.png | adb shell rm /mnt/sdcard/output.png
Related
Below command is to pull a file:
adb -d shell "run-as com.myapp cat /data/data/com.myapp/databases/file.db" > file.db
But how to push it back like Android Studio does via Device File Explorer?
There is no simple command for uploading the file. What Android Studio does when uploading a file using Device File Explorer is this:
Upload the file via adb push to /data/local/tmp/<random file name>
Execute adb shell run-as com.myapp sh -c 'cp /data/local/tmp/<random file name> /data/data/com.myapp/<path>/<final file-name>'
Delete the temp file via adb shell rm /data/local/tmp/<random file name>
Get the updated view for Device File Explorer using adb shell run-as com.myapp sh -c 'ls -al /data/data/com.myapp/<path>/'
I discovered this by capturing the adb traffic on TCP port 5027 using Wireshark. An interesting detail is that each command executed using adb shell command uses the form <command-to-be executed in adb shell> || echo ERR-ERR-ERR-ERR
From Robert's answer now I can do like this:
function dbpull() {
adb shell run-as "com.$1.debug" cat "/data/data/com.$1.debug/databases/$2.db" > "/Users/username/Desktop/$2.db"
}
function dbpush() {
adb push "/Users/username/Desktop/$1.db" "/sdcard/db/tmp/"
}
function dbpush2() {
adb shell run-as "com.$1.debug" cp "/sdcard/db/tmp/$2.db" "/data/data/com.$1.debug/databases/$2.db"
}
function dbcheck() {
adb shell run-as "com.$1.debug" ls -al "/data/data/com.$1.debug/databases/"
}
Just write above code lines in your .bash_profile and then call it in terminal.
dbpull myapp mydata
At this moment I prefer to use Visual Studio Code than Android Studio to develop my Android apps. So, I need to know more about commands in terminal, e.g. adb, gradle, etc.
I hope this would be useful for everyone.
Use this command
adb push <file_path> <android_device_path>
adb pull <android_device_path>
This question already has answers here:
How to use su command over adb shell?
(7 answers)
Running ADB commands through powershell
(1 answer)
Closed 6 years ago.
i am writing batch script for executing adb commands but while executing "SU" commands only the first commands runs "adb shell" and stops
as the script is typing all the commands very fast and not waiting for previous command to run completely so that next command can be entered into the shell window that is "su" example of code is below
:lckscreen
adb shell
su
rm /data/system/gesture.key
rm /data/system/*.key
exit
exit
pause
goto menu4
i also tried
adb shell & su
but still same Result
shell#Samsung_s4:/ $
please help
Please try
adb shell "su -c 'rm /data/system/gesture.key'"
adb shell "su -c 'rm /data/system/*.key'"
and see the question in How to use su command over adb shell?
You will have to create a separate .txt file containing all the shell commands, in example:
su
mount -o remount,rw /system
mv /system/build.prop /sdcard
Make sure to have put an "enter" at the bottom to execute the last command. Now, in the bat file, where you'd normally put adb shell etc. Put adb shell > nameofyourtxt.txt.
If the only command you want to execute is "su", you can do adb shell su.
so I'm trying to run some ADB commands through a powershell script.
This is a simple example of what I am trying to do:
adb shell "
echo "in adb shell"
su root
echo "you are now root."
ls
cd /data/data
echo "in /data/data"
ls
"
I saw in a previous post to add the "" next to shell and at the bottom but that still didn't work for me. I can start the shell and the first ls works. but it just prints the rest of the commands out instead of doing them. The output I am getting looks like:
PS C:\Scripts> & .\test.ps1
: not found/sh:
in adb shell
su root
echo you are now root.
ls
cd /data/data
echo in /data/data
MSM8960_lpm.rc
acct
cache
.
.
.
ueventd.qcom.rc
ueventd.rc
vendor PS C:\Scripts>
Any help would be greatly appreciated. Thanks in advance!
Note: the path to ADB is within the powershell $env:path so the adb commands are working
I was able to get around this by doing:
adb shell "su -c '[cmd]; [cmd]' "
I want to type multiple adb shell commands in one line, for example, i want to type adb shell and su and cd sys together. i tried to connect them with && and & bzw.adb shell && su && cd sys, but it seems like not work with adb commands, but works with windows commands. does anybody knows what is the problem?
Sovled by myself adb shell "su -c 'cd sys'"
I tried the following script written by me.
#!/bin/bash
adb -s 015d2578a7280412 shell ls /data/app > apps.txt
while read line
do
apk=/data/app/$line
adb -s 015d2578a7280412 pull $apk apk-nexus7-default
done < apps.txt
I got errors like:
' does not existdata/app/com.StudioOnMars.CSPortable-1.apk
' does not existdata/app/com.adobe.reader-1.apk
...
When I tried
adb -s 015d2578a7280412 pull /data/app/com.adobe.reader-1.apk apk-nexus7-default
It worked.
Any problem with the piece of scripts?
It's a known issue with adb - that even in linux it is using MSDOS style newline characters - CR+LF ('\r\n') instead of just LF ('\n').
The easiest way to mitigate that is to remove '\r' from the adb output
adb -s 015d2578a7280412 shell ls /data/app | tr -d '\r'> apps.txt
Just do:
$ adb -s 015d2578a7280412 pull /data/app/
pull: building file list...
pull: /data/app/some.apk -> ./some.apk
...