命令执行时关闭CMD窗口 - Java

时间:2017-09-20 09:34:42

标签: java windows cmd sikuli

我正在使用Sikuli执行自动化测试,而我正在编写一个小型Java应用程序来运行我的测试。我已经搜索了其他答案,但大多数都与从java运行批处理脚本有关,我需要从java运行整个命令。我有以下命令从cmd运行Sikuli:

Process p = Runtime.getRuntime().exec("cmd /c start /wait C:\\Sikuli\\runIde.cmd -r C:\\Sikuli\\xmlRunner\\runners\\Runner.sikuli --args 5");
System.out.println("Waiting for command to be executed");
p.waitFor();
System.out.println("Command finished");

这将启动一个新的cmd窗口并开始执行我的脚本,但是当脚本完成时,它不会关闭cmd窗口。有没有办法在我的脚本运行完毕后自动关闭cmd窗口?

1 个答案:

答案 0 :(得分:1)

使用cmd /c start /wait cmd /c C:\\Sikuli\\runIde.cmd -r C:\\Sikuli\\xmlRunner\\runners\\Runner.sikuli --args 5

见dock:

WAIT        Start application and wait for it to terminate.
command/program
            If it is an internal cmd command or a batch file then
            the command processor is run with the /K switch to cmd.exe.
            This means that the window will remain after the command
            has been run.

            If it is not an internal cmd command or batch file then
            it is a program and will run as either a windowed application
            or a console application.

当您直接致电runIde.cmd时,/K开关已应用,但当您使用cmd.exe代理此来电时,此规则不适用。