I am using following command which prints android device logs from connected device buffer in my desktop.
adb logcat
Now requirement is, i am running a test and want to see the output of current action in logs.
That is i need logs only since when i start logging command.
i don't want logs from the buffer or the logs prior to time when logging is started.
Also i don't want to clear the buffer using -c argument. because somebody (some other process) may need buffered traces during testing
adb logcat --live-trace
Thanks in advance for the help.
i found the perfect way to do it!
Read current time from the device only.
adb shell echo $(date +'%Y-%m-%d %H:%M:%S')
Merge the above output with ".000" (just adding milliseconds) and save into some variable say %timestamp%.
Then,
adb logcat -v threadtime - D -T %timestamp%
You can use it in one command:
adb logcat -v threadtime - D -T $(adb shell echo $(date +'%s')).000
Related
I am trying to start a video call on Skype using their URI API, but the video is turned off when the call starts.
They give a clear example how to use it:
skype:skype.test.user.1?call&video=true
I am using adb to send the command, so I am using the command:
adb shell am start -a android.intent.action.VIEW -d "skype:someuser?call&video=true"
This successfully initiates the call, but with video off. I have tried adding the extra parameter using the Android adb extra parameters:
--es extra_key extra_string_value
So my full command is
adb shell am start -a android.intent.action.VIEW --es "video" "true" -d skype:someuser?call
but this doesn't make the trick.
Figured out the solution thanks to this related answer.
The solution is simply to escape the ampersand (&) character inside the quotes!
So, the final command that worked for me is:
adb shell am start -a android.intent.action.VIEW -d "skype:someuser?call\&video=true"
I'm writing script to run iperf on linux device accessible via adb.
From a terminal, when I run the command: adb shell iperf -c ......
I get the log of the command 50 s after the command starting.
inconvenient: during 50 s you are not sure that iperf has started
I tried the logcat command (logcat --pid ...), It gives the same result.
From a terminal, when I enter adb session first and then I run the command: iperf -c .....
I get the log of the command in real time.
inconvenient: I'm not able to automate the procedure, because I have to start the adb session first
For the first use case: Is there a way to force "log flush" in order to get the log in real time?
For the second use case: Is there a way to send commands to already opened adb shell session?
Is there any other ways to launch iperf on device and get the log in real time?
The solution i found is the library pexpect that allow to interact with adb session.
I have a program running on armbian single board computer. The program starts with -b option during the startup of the system. I created this simple shell script
#!/bin/bash
#Myprog server start
sudo -b /home/myprog/myprog
This program is C written and it sometimes outputs some information with printf functions. But since it is started with -b option there's is noting in the console.
Now when I log in to the armbian via ssh with Putty I want to occasionally read the output of this program. Is it even possible?
Not exactly what you’re asking, but generally speaking it’s better practice to redirect output to a log file than to try to interactively look at the console output for a background app.
Something like:
sudo -b /home/prog/myprog >> /home/prog/log.txt 2>&1
Should do it.
Then view output with
tail -f /home/prog/log.txt
If it’s really important to you to run interactively without logs, I would suggest running it from within “screen” without backgrounding it.
screen
sudo /home/prog/myprog
Then ctrl-d to detach and let it run in background. screen -r to reattach.
How do you take a screenshot via ADB for Android Things? I have tried:
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png
adb shell rm /sdcard/screen.png
and
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png
I couldn't make screepcap work in Android Things Developer Preview. The command results in a 0-size file.
That said, I recommend the following two options: either use the framebuffer or record a video (screenrecord seems to work) and convert it to an image later on by proper tool. I'll consider the first option, so the steps would be:
Pull the framebuffer to the host machine. Note that you need to start adbd as root in order to pass a permission check:
adb root
adb pull /dev/graphics/fb0 screenshot
Convert the raw binary to image by the tool you prefer. I'm using ffmpeg. The command below might not work for you due to different screen resolution or pixel format. If so, make proper changes.
ffmpeg -f rawvideo -pix_fmt rgb565 -s 800x480 -i screenshot screenshot.png
Seems, because of old limited OpenGL version in Android Things, described by Tatsuhiko Arai here there is no possibility to get screenshot via ADB, but You can record video (e.g. from Android Studio, or via ADB commands) and than grab frame from it, for example via ffmpeg:
ffmpeg -i device-2017-01-23-193539.mp4 -r 1 screen-%04d.png
where device-2017-01-23-193539.mp4 - name of recorded (via Android Studio) file .
I've tried exactly this code with a little bit change like below (but no matter) and it works well. The image is in my platform-tools directory now.
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png screen.png
adb shell rm /sdcard/screen.png
I am trying to create a batch file that will do some ADB commands that I use on a daily basis. I am stuck with adb logcat because the logcat never ends. Is there a way to end it after so many seconds? Currently I have
:logcat
adb logcat
pause>nul|set /p "=Press any key to return to the menu"<nul&echo(
cls
goto start
Thinking that pause would allow me to manually end it when I was done getting what I needed from the log.
Is there a way to end the command?
Thanks
You could use
timeout DURATION adb logcat
to stop the logcat after DURATION (default is in seconds).
Another way of using adb is:
adb logcat -d
This will get the log and terminate the command immediately.
I don't know any other way to stop the logcat after some seconds, except CTRL+C.