赞
踩
使用安装封装 runtime
echo(new String[]{“echo 1 > /sys/bus/text”}); //调用方式
private void echo(String[] command) {
DualExecutor.getExecutorService().execute(() -> {
try {
Process process = Runtime.getRuntime().exec(“sh”);
DataOutputStream outputStream = new DataOutputStream(process.getOutputStream());
for (String tmpCmd : command) {
Log.d(TAG,“tmpCmd:”+tmpCmd);
outputStream.writeBytes(tmpCmd + “\n”);
}
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
Log.e(TAG, “ex” + e.toString());
}
});
}
使用java 封装类 ProcessBuilder
//d调用方法
String[] cmds = {“logcat”, “|”, “grep”, “test”};
onCmd(cmds);
/**
* 执行MFD 工具
*
* @param cmds
*/
private void onCmd(final String[] cmds) {
Log.e(TAG, “onCmd”);
DualExecutor.getExecutorService().execute(() -> {
ProcessBuilder processBuilder = new ProcessBuilder(cmds);
processBuilder.redirectErrorStream(true);
Process process = null;
try {
process = processBuilder.start();
printCmdLog(process.getInputStream());
process.waitFor();
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG, “CMD 异常” + e.toString());
}
});
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。