简体   繁体   English

从Java调用时隐藏BAT文件窗口

[英]Hide BAT file window when invoking it from Java

I'm invoking the execution of a BAT file from Java with the Runtime object. 我正在使用Runtime对象从Java调用BAT文件的执行。

Is it possible to hide the BAT window during the execution of the script? 是否可以在执行脚本期间隐藏BAT窗口? How is it possible? 这怎么可能?

Try using javaw rather than java to run the script. 尝试使用javaw而不是java来运行脚本。

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

Update: Sorry, I think I read the question wrong. 更新:对不起,我想我读错了。 I know I've suppressed a .bat window doing something along these lines before: 我知道我已经压制了一个.bat窗口,然后在这些行中执行某些操作:

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

Invoke start as the first command in your process builder, with the /b option: 使用/b选项调用start作为流程构建器中的第一个命令:

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

The /b options suppresses the command window. /b选项禁止命令窗口。

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

In scriptName.vbs you write 在scriptName.vbs中你写

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM