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

标签 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窗口?

最佳答案

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

查看 jetty :

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

关于java - 命令执行时关闭 CMD 窗口 - Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46318407/

相关文章:

java - 使用 Android 模式实现电子邮件 validator

c# - 我可以在不同的线程中过滤来自窗口的消息吗?

c++ - 以编程方式重新连接断开的 VHD 链

batch-file - “ls”不被识别为内部或外部命令、可操作程序或批处理文件

node.js - 在 Node.js 命令提示符中更改目录

windows - 在 Windows 7 上以不同用户身份运行的单行命令也包含密码

java - 我可以将 Guice 中的 @Transactional 与 Google App Engine 的数据存储一起使用吗?

java - 在 Eclipse 中插入代码模板时出现空行

python - Windows Defender 将 Python EXE 检测为木马

java - 如何使用 Python 生成 AST(以 XML 表示)的控制流?