简体   繁体   中英

How to redirect data of dmesg using Runtime.exec?

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
...

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM