繁体   English   中英

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

[英]Close CMD window when command executes - Java

我正在使用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窗口?

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

见码头:

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代理此调用时,此规则将不适用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM