日期:2014-05-20 浏览次数:20697 次
String[] cmd = new String[]{"/home/a/linuxshell.sh"};
Process ps = Runtime.getRuntime().exec(cmd);
BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
StringBuffer sb = new StringBuffer("正常信息:");
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
br.close();
sb.append("\n错误信息:");
br = new BufferedReader(new InputStreamReader(ps.getErrorStream()));
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
br.close();
System.out.println(sb.toString());