Android下执行Runtime.getRuntime().exec后返回状态

private String doExec(String cmd)返回输出值,private String doExec2(String cmd)返回错误列表。你如果有不明白的地方,可以给我留言。
private String doExec(String cmd) {
String s = "\n";
try {
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
s += line + "\n";
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return s;
}


private String doExec2(String cmd) {
String s = "\n";
try{
Process ps=Runtime.getRuntime().exec(cmd);
DataInputStream ise = new DataInputStream(ps.getErrorStream());
String error = null;
while((error = ise.readLine()) != null) {
s += error + "\n";
}
}
catch(IOException ex){
String temp = ex.getMessage();
Log.i("doInBackground", temp);
}
return s;

}

你可能感兴趣的:(android,app)