java调用操作系统命令

String command = "/sbin/ifdown eth0";
log.debug("Process command: " + command);
Process proc = Runtime.getRuntime().exec(command);
InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
log.error("<Runtime Message>");
while ((line = br.readLine()) != null) {
log.error(line);
}
log.error("</Runtime Message>");
exitVal = proc.waitFor();
log.debug("Process exitValue: " + exitVal);
return exitVal;

你可能感兴趣的:(java)