1

Problem 1: I want to redirect the kernel log to other file using my app. How to properly execute this? The code is something like below:

Runtime.getRuntime().exec("dmesg > /data/kernel_log.txt"); 

Problem 2: I want to clear the kernel log using my app. How to correct the below code;

Runtime.getRuntime().exec("dmesg -c"); 

Note1: My goal is to get all the log of the kernel(dmesg) from START to LATEST. Since dmesg has buffer size limitation and I don't want to rebuild the kernel just to resize the buffer.

Note2: this is very related to; android : how to run a shell command from within code

Note3: Currently I am using a device with a ENG mode build, which means this is rooted am I correct?

Logcat Error Message:

11-11 20:18:47.910: E/DmesgGetterService(2885): java.io.IOException: Error running exec(). Command: [dmesg > /data/kernel_log.txt] Working Directory: null Environment: null
...
11-11 20:19:07.920: E/DmesgGetterService(2885): Caused by: java.io.IOException: No such file or directory
...
Community
  • 1
  • 1
quiel
  • 427
  • 1
  • 3
  • 19
  • 1
    I have never worked with android, but if it is as similar to "Desktop-Linux" as I suspect, you should be able to obtain the dmesg-info from the /proc filesystem. IIRC dmesg is just an abbreviation for printing the virtual file /proc/kmesg. – Jonathan Nov 11 '11 at 11:51
  • Yes, I can get the kernel log using: Runtime.getRuntime().exec("dmesg"); – quiel Nov 11 '11 at 12:01
  • The problem is I cannot redirect the output to other file. I can make use of the FileOutputStream but this may take lots of memory usage since I am going to loop line by line. – quiel Nov 11 '11 at 12:05

1 Answers1

0

I was able to get the dmesg log in different method. Using the AlarmManager to run a service in the specified interval I fetch the log from the kernel then find the last line I copied from previous run then append the new logs. That's it!

quiel
  • 427
  • 1
  • 3
  • 19
  • Can you please post the detailed solution. I am trying to redirect the output of dmesg to a file in sdcard. I have included the permissions to write and read from sdcard. ( Runtime.getRuntime().exec("dmesg > /sdcard/file_name.txt"). Also, is it necessary to have root permissions to run this command ? – Shravya Boggarapu Jun 14 '18 at 13:51