java cmd execute

sunj2007發表於2013-08-08
Read cup info

public static String fetch_cpu_info() {
String result = null;
CMDExecute cmdexe = new CMDExecute();
try {
String[ ] args = { “/system/bin/cat”, “/proc/cpuinfo” }
result = cmdexe.run(args, “/system/bin/”);
Log.i(”result”,”result=” + result);
} catch (IOException ex) {
ex.printStackTrace();
}
return result;
}

java.lang.Process p = Runtime.getRuntime().exec(cmdStrings);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
Slog.v("Jason", line + "/n");
}

BufferedReader in2 = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((line = in2.readLine()) != null) {
Slog.v("Jason", "error " + line + "/n");
}
p.waitFor();

ps:下面的返回值必須及時的讀出,否則會形成堵塞,後面的執行不到
p.getInputStream()
p.getErrorStream()


From:
http://blog.csdn.net/fuuckwtu/article/details/6366912

相關文章