Hide BAT file window when calling it from Java

I am invoking the execution of a BAT file from Java using a Runtime object.

Is it possible to hide the BAT window during script execution? How is this possible?

+3


source to share


3 answers


Try using javaw instead of java to run your script.

http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/java.html



Update: Sorry, I think I read this question wrong. I know I suppressed the .bat window doing something along these lines before:

http://www.geekstogo.com/forum/topic/56092-hide-the-command-prompt-windows/

+1


source


Call start

as the first command in your process builder, with the option /b

:

ProcessBuilder builder = new ProcessBuilder("start", "/b", "<mybatchcommand>");
// .. set environment, handle streams
builder.start();

      



Parameters /b

suppress the command window.

+1


source


 Process p = Runtime.getRuntime().exec("scriptName.vbs");

      

In scriptName.vbs you write

var WindowStyle_Hidden = 0
var objShell = WScript.CreateObject("WScript.Shell")
var result = objShell.Run("cmd.exe /c abc.bat", WindowStyle_Hidden)

      

0


source







All Articles