您的位置:首页 > 移动开发 > Android开发

Android Runtime.getRuntime().exec

2017-09-24 07:59 423 查看
try {
// Executes the command.
Process process = Runtime.getRuntime().exec(cmd);

// NOTE: You can write to stdin of the command using
// process.getOutputStream().
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();

// Waits for the command to finish.
process.waitFor();

return output.toString();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}


String mProjectName = doCommand("cat /proc/version").trim();
Log.d(TAG, "mProjectName =" + mProjectName);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: