关于Runtime.getRuntime().exec(cmd);问题,请求大神帮忙解决,昨天一晚上没搞出来
1 需求,利用java程序重启tomcat
2 看程序
package com.idt.common;
import java.io.BufferedReader;
import
java.io.IOException;
import java.io.InputStreamReader;
import java.util.Date;
public class TomcatReset {
public void TomcatShutDown(String Path1){
Runtime runtime = Runtime.getRuntime();
try {
Process process = runtime.exec(Path1);
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String s;
boolean restart = false;
while ((s = in.readLine()) != null) {
restart = true;
break;
}
System.out.println("<" + new Date() + "> Tomcat is stop "
+ (restart ? "OK" : "ERROR"));
System.out.println("成功停止服务");
} catch (
IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void TomcatStart(String Path2){
Runtime runtime = Runtime.getRuntime();
try {
Process process = runtime.exec(Path2);
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String s;
boolean restart = false;
while ((s = in.readLine()) != null) {
restart = true;
break;
}
System.out.println("<" + new Date() + "> Tomcat is start "
+ (restart ? "OK" : "ERROR"));
System.out.println("成功启动服务");
} catch (IOException e) {
// TODO Auto-genera