使用java执行批处理文件后无法关闭命令提示符
我正在使用此行调用 build.bat 文件
rt.exec(new String[]{"cmd.exe","/C","start", "/MIN","build.bat"});
此行打开命令提示符。构建成功,但窗口保持打开状态。 我该如何关闭它? 尝试破坏进程和其他 System.ext 方法。没用
I am invoking the build.bat file using this
rt.exec(new String[]{"cmd.exe","/C","start", "/MIN","build.bat"});
This line opens a command prompt. The build is successful but the window remains open.
How do I close it?
Tried destroying the process and other System.ext methods. no use
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您不需要在参数中使用
start /MIN
。你试过这个吗?You shouldn't need to use
start /MIN
in your arguments. Have you tried this?在bat文件末尾添加
exit
,也无需在前面添加cmd
即可直接执行batat the end of bat file add
exit
,also no need to addcmd
ahead you can directly execute bat我刚刚开始,所以不能投票支持@Franci Penov 的答案是正确的:
或者简单地说,
不应该弹出命令提示符。
build.bat
将无头执行。假设您确实想在
build.bat
运行时调出命令提示符(这样您就可以直接从命令提示符看到输出,而不是稍后再处理),并且希望命令提示符消失build.bat
完成执行后,您可以使用以下命令:start
启动一个(可见的)命令提示符窗口来处理和显示cmd 的输出。 exe /C 批处理.bat
。如果您在batch.bat
末尾有一个pause
,那么您所需要做的就是按一个键,命令提示符就会消失,无需键入在提示窗口中exit
将其关闭。这可能不是您所需要的,但我一直在搜索,但后来自己找到了解决方案。只是为了分享。
I am just starting out here in SO, so couldn't upvote @Franci Penov's answer as correct:
or simply,
should not bring up a command prompt.
build.bat
will be executed headlessly.Suppose you do want to bring up a command prompt while
build.bat
is running (so you can see the output right from the command prompt instead of processing it later), and want the command prompt to go away afterbuild.bat
has finished execution, you may use the following:the
start
starts a (visible) command prompt window to process and display the output ofcmd.exe /C batch.bat
. If you have apause
at the end of yourbatch.bat
then all you need to do is hitting a key, and the command prompt will go away without the need to typeexit
at the prompt window to close it.This may not be what you need, but I have been searching on SO but then found out the solution myself. Just to share it.
这是我在 StackOverflow 上找到的修复 ,用于在使用批处理文件执行程序后关闭命令提示符。
而不是:启动“某个程序路径”,
请执行以下操作:启动“”“某个程序路径”
在 Windows XP 下适用于我。
This is a fix I found on StackOverflow, for closing a command prompt, after executing a program using a batch-file.
Instead of: start "some program path"
do this: start "" "some program path"
Works for me under Windows XP.
只需使用新行更新批处理 (.bat) 文件并在该新行中键入:
exit
。Just update your batch (.bat) file with a new line and type in that new line :
exit
.