我正在 eclipse 中使用 ANT 运行 selenium TestNG 脚本。执行完成,但当我尝试从 java 运行 bat 文件时,即使执行后,cmd 提示符仍保留在那里。但是当我通过双击运行bat文件时,cmd在执行后退出。下面是调用bat文件的代码以及bat文件的内容:
Runtime.getRuntime()
.exec("cmd /c start run.bat", null, new File("C:\\Users\\nvithushan\\Desktop\\HSBC\\gen\\seleniumwebdriver\\HSBC_Demo"));
这是批处理文件的内容。
@echo off
echo exectution starting
start ant
exit
任何帮助
最佳答案
在您的 exec 中执行 cmd/c run.bat
就足够了,在批处理文件中只需执行 ant.bat
或 call ant.bat
即可。根据定义,start 命令启动一个单独的 cmd 进程。另请注意文档:
If [the command you run] 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.
关于java - 在cmd中执行后退出bat文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25911689/