简体   繁体   English

如何使用Runtime.exec重定向dmesg的数据?

[英]How to redirect data of dmesg using Runtime.exec?

Problem 1: I want to redirect the kernel log to other file using my app. 问题1:我想使用我的应用程序将内核日志重定向到其他文件。 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. 问题2:我想使用我的应用清除内核日志。 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. 注意1:我的目标是从START到LATEST获取内核(dmesg)的所有日志。 Since dmesg has buffer size limitation and I don't want to rebuild the kernel just to resize the buffer. 由于dmesg具有缓冲区大小限制,我不想重建内核只是为了调整缓冲区大小。

Note2: this is very related to; 注意2:这与很相关; android : how to run a shell command from within code android:如何从代码内运行shell命令

Note3: Currently I am using a device with a ENG mode build, which means this is rooted am I correct? 注意3:当前,我正在使用具有ENG模式构建的设备,这意味着这是扎根的,对吗?

Logcat Error Message: Logcat错误消息:

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. 我能够以其他方法获取dmesg日志。 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. 使用AlarmManager在指定的间隔内运行服务,我从内核中获取日志,然后找到我从上次运行中复制的最后一行,然后追加新日志。 That's it! 而已!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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