这可能是由于Tomcat应用程序正在从非交互式终端运行命令导致的。解决此问题的方法是在命令字符串中添加start /B,以使其成为后台进程,并在不使用交互式shell的情况下运行。以下是一个示例,它通过运行Windows命令快速打开记事本,然后查看它是否正在后台运行,并检查退出代码:
CommandLine command = new CommandLine("cmd");
command.addArgument("/c");
command.addArgument("start");
command.addArgument("/B");
command.addArgument("notepad");
DefaultExecutor executor = new DefaultExecutor();
int exitValue = executor.execute(command);
System.out.println("Notepad started with exit code " + exitValue);