Windows: start a new process hidden (no window)

爱⌒轻易说出口 提交于 2019-12-24 03:42:47

问题


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.


回答1:


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).

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

This script allows you to run any .bat file invisibly with the following command:

wscript.exe "C:\Path\To\File\invisible.vbs" "C:\Path\To\Another\File\BatFile.bat"

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 with start 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.




回答2:


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).



来源:https://stackoverflow.com/questions/8936451/windows-start-a-new-process-hidden-no-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!