Daniel
Daniel

Reputation: 2117

Windows: start a new process hidden (no window)

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.

Upvotes: 2

Views: 5264

Answers (2)

Jeffrey
Jeffrey

Reputation: 44798

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.

Upvotes: 1

cheeken
cheeken

Reputation: 34655

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

Upvotes: 0

Related Questions