您的位置:首页 > 编程语言 > Java开发

Java执行命令行问题

2015-09-17 20:56 495 查看
String launchTime = "";
try {

String logcatCommand = "adb shell logcat -v time -d ActivityManager:I *:S";
Process process = Runtime.getRuntime().exec(logcatCommand);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";

StringBuilder strBuilder = new StringBuilder();
while ((line = bufferedReader.readLine()) != null) {
strBuilder.append(line);
String regex = ".*Displayed.*" + PACKAGE_NAME + ".*\\+.*ms.*";
//System.out.println(line);
if (line.matches(regex)) {
if (line.contains("total")) {
launchTime = line.substring(line.lastIndexOf("+") + 1, line.lastIndexOf("ms") + 2);
break;
}
}
}
process.waitFor();
System.out.println(strBuilder);

} catch (IOException e) {

} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

if(launchTime.equals("")) {
launchTime = "N/A";
}


http://www.mzone.cc/article/213.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: