Last active
December 10, 2015 08:08
-
-
Save wcypierre/4405322 to your computer and use it in GitHub Desktop.
[Article]Workaround for grep and Logcat, dmesg, and last_kmsg on Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In this article, I will explain some of the confusions that may occur whilst using grep in logcat, dmesg, kmsg and last_kmsg on different platforms,mainly between Unix(Linux based such as ubuntu, linux mint, fedora, BSD based such as netbsd, freebsd, and even Mac) and Windows(Windows XP, Windows Vista, Windows 7, Windows 8 and etc). | |
[SIZE="4"][B]Requirements[/B][/SIZE]: | |
[LIST=1] | |
[*]Known about the existence of logcat, dmesg, kmsg, and last_kmsg and have tried logging it at least once | |
[*]Know some basic knowledge of batch/bash(cmd/terminal) | |
[*]Using Windows OS(The problem only lies on Windows, so if you're using Mac or Linux then you're fine) | |
[/LIST] | |
Although this is a rather technical article, but I will make it as simple as possible for all of the users to understand :) | |
Sometimes, I will see some of the developers will issue similar to this: | |
[SIZE="4"][B]Log Commands with Grep[/B][/SIZE] | |
[QUOTE] | |
[B]Logcat[/B]: | |
adb logcat | grep 'htc' | |
[B]Dmesg[/B]: | |
adb shell dmesg | grep 'mp_decision' | |
[B]last_kmsg[/B]: | |
adb shell cat /proc/last_kmsg | grep 'mp_decision'[/QUOTE] | |
[SIZE="4"][B]So, the problem is?[/B][/SIZE] | |
The problem is that if you're using a Windows OS, Windows OS doesn't have grep installed, so your command would not run and you will see an error message like this: | |
[IMG]http://i1352.photobucket.com/albums/q647/wcypierre/XDA%20Windows%20Grep%20Workaround/adbgrepwindowserror_zps2961e162.png[/IMG] | |
Linux or Mac users will not have this problem as they have grep installed, so they are fine. | |
[SIZE="4"][B]Workaround[/B][/SIZE]: | |
1. Install a Linux shell on Windows | |
2. Use a terminal app within the Android phone | |
3. Connect to the linux shell inside the Android Phone by using your computer | |
4. Use the built-in filters(for logcat ONLY) | |
[SIZE="4"][B]Workaround #1[/B][/SIZE] | |
[QUOTE]You can simply click [URL="http://forum.xda-developers.com/showthread.php?t=2072090"]here[/URL] and follow the simple steps to get a linux shell on your computer :) | |
[/QUOTE] | |
[SIZE="4"][B]Workaround #2[/B][/SIZE] | |
[QUOTE]You just need to download a terminal app from your phone and every command will work fine. You would need to omit the adb and adb shell keyword(refer below) in order for the command to work. A nice terminal app suggestion would be [URL="https://play.google.com/store/apps/details?id=jackpal.androidterm&hl=en"]https://play.google.com/store/apps/details?id=jackpal.androidterm&hl=en[/URL] which you can simply download from Google Playstore | |
[/QUOTE] | |
[SIZE="4"][B]Workaround #3[/B][/SIZE] | |
[QUOTE]You can just type "adb shell" and press enter, then type your commands(omit all adb and adb shell keyword) and it will work just as like in workaround #2. | |
[/QUOTE] | |
[SIZE="3"][B]Example[/B][/SIZE] | |
[QUOTE]1. "[B]adb shell[/B]" + enter | |
2. Choose the command that you wanted: | |
[B]Logcat[/B]: | |
logcat | grep 'htc' | |
[B]Dmesg[/B]: | |
dmesg | grep 'mp_decision' | |
[B]last_kmsg[/B]: | |
cat /proc/last_kmsg | grep 'mp_decision'[/QUOTE] | |
[SIZE="4"][B]Workaround #4[/B][/SIZE] | |
[QUOTE]This workaround is a workaround which only exists for logcat, because logcat have a filtering system that is built into it(makes us wonder why it is not built into dmesg and last_kmsg as well eh?). | |
For example, the grep command for the logcat above can be replaced by: | |
[QUOTE]adb logcat htc:V *:S[/QUOTE] | |
However, the downside is that you need to know the exact name of the app which is logged at the logcat in order to search for it while you can do a random keyword search with grep which helps a lot if you do not know what to look for. | |
For more information about the filtration, you can refer to [URL="http://developer.android.com/tools/debugging/debugging-log.html"]http://developer.android.com/tools/debugging/debugging-log.html[/URL][/QUOTE] | |
[SIZE="4"]Conclusion[/SIZE]: | |
Hopefully, after reading this article, you will know how to deal with grep when you're on Windows OS :) | |
Do drop me a question or two if you have something that you don't understand and stay tuned for more articles! :highfive: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment