日期:2014-05-18 浏览次数:20933 次
public String execShellPingCmd(String cmd) {
String[] command = new String[] {"/usr/bin/sh", "-c", cmd};
Process process;
try {
process = Runtime.getRuntime().exec(command);
// try {
// process.waitFor();
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
LineNumberReader lr = new LineNumberReader(new InputStreamReader(process.getInputStream()));
StringBuffer sb = new StringBuffer();
// BufferedReader bis = new BufferedReader(new InputStreamReader(
// process.getInputStream()));
String s_temp1 = null;
while ((s_temp1 = lr.readLine()) != null) {
sb.append(s_temp1).append("\n");
}
return sb.toString();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}