当前位置: 代码迷 >> java >> 尝试在后台运行时未执行批处理文件
  详细解决方案

尝试在后台运行时未执行批处理文件

热度:49   发布时间:2023-07-17 20:18:27.0

我正在尝试从Java类执行一些批处理文件。 我希望批处理在不打开cmd窗口的情况下运行,我想等到完成为止。

当使用下面的命令(没有背景)时,它可以完美地工作:

String executeCmd = "cmd /c start /wait " +config.getJarPath()+ " --context_param Path=" +folderName;
        final Process process = run.exec(executeCmd);
        process.waitFor();

但是,当我添加/ b(在后台运行)时,批处理文件未运行:

String executeCmd = "cmd /c start /B /wait " +config.getJarPath()+ " --context_param Path=" +folderName;
        final Process process = run.exec(executeCmd);
        process.waitFor();

你有什么想法吗?

非常感谢

使用start /b命令标签只需在当前窗口中启动程序。

B           Start application without creating a new window. 

如果要将批处理文件作为隐藏进程启动,则有一个简单的可以执行此操作。

或者,您可以使用并在转换时指定您希望exe成为Ghost应用程序

/B/wait一起使用时,它可以工作。

例如, cmd /c start /B /wait yourbatfile.bat