dlio 发表于 2013-8-21 09:03:56

利用cmd对tomcat进行重启操作

由于需要在固定的时候对tomcat进行关闭,所以写了个小例子,利用cmd命令对tomcat进行重启

public class Restart {

   public static void main(String[] args) {
       String dir = "C:\\vvv   mmm\\apache-tomcat-6.0.30\\bin\\";


       Runtime run = Runtime.getRuntime();

       String[] command = new String[]{"cmd","/C","call","startup.bat"};
       try {
         run.exec(command, null, new File(dir));
       } catch (Exception e) {
         e.printStackTrace();
       }

       System.out.println("启动");

       try {
         Thread.sleep(30000);
       } catch (InterruptedException e) {
         e.printStackTrace();
       }

       System.out.println("关闭");

       String[] command2 = new String[]{"cmd","/C","call","shutdown.bat"};
       try {
         run.exec(command2, null, new File(dir));
       } catch (IOException e) {
         e.printStackTrace();
       }


       try {
         Thread.sleep(30000);
       } catch (Exception e) {
         e.printStackTrace();
       }


       System.out.println("重启");

       String[] command3 = new String[]{"cmd","/c","start","startup.bat"};
       try {
         run.exec(command3, null, new File(dir));
       } catch (Exception e) {
         e.printStackTrace();
       }

       System.out.println("nihao");

       try {
         Thread.sleep(10000);

         String[] command4 = new String[]{"cmd","/c","call","tskill","cmd"};
         run.exec(command4);
         System.out.println("关闭cmd进程");
       } catch (Exception e) {
         e.printStackTrace();
       }
   }
}


gmdzxx 发表于 2013-8-22 06:34:44

有竞争才有进步嘛

hyzqb 发表于 2013-8-22 22:27:18

我不在江湖,但江湖中有我的传说。

果果、 发表于 2013-8-23 18:01:38

看尽天下A片,心中自然无码~

kution 发表于 2013-8-24 19:31:43

我是来刷分的,嘿嘿

luobo2ni 发表于 2013-8-25 03:15:13

不知该说些什么。。。。。。就是谢谢

gznz12345 发表于 2013-8-25 10:29:54

我在马路边丢了一分钱
页: [1]
查看完整版本: 利用cmd对tomcat进行重启操作