使用java执行批处理文件后无法关闭命令提示符

发布于 2024-10-10 19:00:29 字数 192 浏览 5 评论 0原文

我正在使用此行调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

╰つ倒转 2024-10-17 19:00:29

您不需要在参数中使用 start /MIN 。你试过这个吗?

rt.exec(new String[]{"cmd.exe","/C","build.bat"});

You shouldn't need to use start /MIN in your arguments. Have you tried this?

rt.exec(new String[]{"cmd.exe","/C","build.bat"});
夜雨飘雪 2024-10-17 19:00:29

在bat文件末尾添加exit,也无需在前面添加cmd即可直接执行bat

at the end of bat file add exit ,also no need to add cmd ahead you can directly execute bat

漫雪独思 2024-10-17 19:00:29
writer.write("expdp greenbuds/greenbuds directory=backup dumpfile="+dd+".dump logfile="+dd+".log");
writer.newLine();
writer.write("Exit");
writer.write("expdp greenbuds/greenbuds directory=backup dumpfile="+dd+".dump logfile="+dd+".log");
writer.newLine();
writer.write("Exit");
旧伤慢歌 2024-10-17 19:00:29

我刚刚开始,所以不能投票支持@Franci Penov 的答案是正确的:

rt.exec(new String[]{"cmd.exe","/C","build.bat"}); 

或者简单地说,

rt.exec("cmd.exe /C build.bat");

不应该弹出命令提示符。 build.bat 将无头执行。


假设您确实想在 build.bat 运行时调出命令提示符(这样您就可以直接从命令提示符看到输出,而不是稍后再处理),并且希望命令提示符消失build.bat 完成执行后,您可以使用以下命令:

rt.exec("cmd.exe /C start cmd.exe /C batch.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:

rt.exec(new String[]{"cmd.exe","/C","build.bat"}); 

or simply,

rt.exec("cmd.exe /C build.bat");

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 after build.bat has finished execution, you may use the following:

rt.exec("cmd.exe /C start cmd.exe /C batch.bat");

the start starts a (visible) command prompt window to process and display the output of cmd.exe /C batch.bat. If you have a pause at the end of your batch.bat then all you need to do is hitting a key, and the command prompt will go away without the need to type exit 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.

作死小能手 2024-10-17 19:00:29

这是我在 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.

初见终念 2024-10-17 19:00:29

只需使用新行更新批处理 (.bat) 文件并在该新行中键入:exit

Just update your batch (.bat) file with a new line and type in that new line : exit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文