java 执行command

时间:2024-04-16 13:10:08
      StringBuffer buf = new StringBuffer(1000);
try {
Process pos = Runtime.getRuntime().exec("sh " + cmd);
pos.waitFor();
InputStreamReader ir = new InputStreamReader(pos.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String ln="";
while ((ln =input.readLine()) != null) {
buf.append(ln+"<br>");
}
logger.info(buf.toString());
input.close();
ir.close();
} catch (Exception e) {
logger.error("###flush Kerberos command error:" + e);
}