【问题标题】:How can I change this code so that the command prompt closes when it finishes executing?如何更改此代码以使命令提示符在完成执行后关闭?
【发布时间】:2012-06-29 16:43:51
【问题描述】:
Runtime.getRuntime().exec("cmd /c start rake.bat");

我希望它运行 rake.bat,然后在完成后关闭命令行。我做过一次,但忘记了我做了什么。我正在使用 Java。

【问题讨论】:

    标签: java batch-file command


    【解决方案1】:

    您可能只是不需要start 命令:

    Runtime.getRuntime().exec("cmd /c rake.bat");
    

    【讨论】:

      【解决方案2】:

      Runtime 对象存储在一个变量中以使用它,然后在完成后调用它的exit() 方法。

      退出(整数状态)

      通过启动终止当前运行的 Java 虚拟机 它的关机顺序。

      不存储在变量中:

      Runtime.getRuntime().exit(0);
      

      【讨论】:

        【解决方案3】:

        要关闭命令行,请使用这个 ...

         Runtime.getRuntime().exec("cmd exit");
        

        【讨论】:

          猜你喜欢
          • 2015-09-16
          • 1970-01-01
          • 2017-10-11
          • 2014-04-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多