Windows:隐藏启动新进程(无窗口)
我想执行第 3 方程序(在我的例子中是 VLC),而不在 Windows 中弹出任何窗口。我正在将我的 java 程序作为 Windows 服务运行,工作正常,但是当我使用 Runtime.exec() 启动 VLC 时,无论我做什么,都会弹出一个窗口。 VLC 的命令行参数阻止了 GUI,但随后会弹出一个黑色控制台 - 也好不了多少。
那么:知道如何从 Java 启动外部程序以便不显示可见窗口吗? (它在 Mac OS X 中工作得很好,我认为 Linux 也一样)
我知道有一种方法可以直接将 libVLC
集成到 Java 程序中,但该选项对我不起作用。
I want to execute a 3rd party program (VLC in my case) without any window popping up in Windows. I am running my java program as a Windows service which works fine, but when I start VLC using Runtime.exec()
then a window pops up, no matter what I do. There's command line arguments to VLC that prevent the GUI but then a black console pops up - not much better.
So: Any idea how to start an external program from Java so that no visible window shows up? (It works just fine in Mac OS X and I assume Linux will be the same)
I know there is a way to directly integrate libVLC
into your Java program but that option does not work for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能有比这更好的解决方案,但这应该有效。
如果安装了 Windows 脚本(Win98 及更高版本上的标准),请将以下行保存为
.vbs
文件(例如invisible.vbs
)。此脚本允许您使用以下命令以不可见的方式运行任何
.bat
文件:此脚本基于 cheeken 回答,因为它将允许您隐藏 cmd 控制台。您所要做的就是创建一个包含
start vlc
的.bat
文件。注意:如果您使用此脚本执行
.bat
文件,它必须自行关闭,并且不能抛出导致挂起的错误。如果确实如此,它将一直存在,直到关闭或直到您通过任务管理器将其关闭。There's probably a better solution than this, but this should work.
If you have Windows Scripting installed (standard on Win98 and newer) save the following line as a
.vbs
file (invisible.vbs
, for example).This script allows you to run any
.bat
file invisibly with the following command:This builds on cheeken's answer because it will allow you to hide the cmd console. All you have to do is create a
.bat
file withstart vlc
in it.Note: If you execute a
.bat
file with this script, it has to close itself and it cannot throw an error which causes it to hang. If it does it will stick around until shutdown or until you close it through the task manager.不要直接在控制台命令中调用 VLC 二进制文件,而是尝试调用
start
反对该命令(即start c:\vlc.exe
)。请注意,此调用或多或少会立即返回(因此,如果您的应用程序依赖于返回的调用来确定 VLC 何时终止,则必须以其他方式产生)。
Instead of calling the VLC binary directly in your console command, try calling
start
against that command (i.e.,start c:\vlc.exe
).Note that this call will return more or less immediately (so if your application is depending upon the call returning in order to determine when VLC has been terminated, it will have to yield some other way).