javascript 想在使用 WshShell.Exec 方法时隐藏命令提示符窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15128517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Want to hide command prompt window in using WshShell.Exec method
提问by user2118354
I want to execute a java program from a javascript and want to get the output.
我想从 javascript 执行一个 java 程序并想获得输出。
Intailly i tried with below code:
我最终尝试使用以下代码:
WshShell = new ActiveXObject("WScript.Shell");
var launch="cmd.exe /c java -classpath . HelloWorld ";
var cmdRun = WshShell.Run(launch,0,true);
Through Run method i am not able get the output of the class.
通过 Run 方法,我无法获得类的输出。
Then i tried with below code:
然后我尝试使用以下代码:
WshShell = new ActiveXObject("WScript.Shell");
var launch="cmd.exe /c p java classpath . HelloWorld ";
var cmdRun = WshShell.Exec(launch);
while (cmdRun.Status == 0) // wait for the command to finish
{
sleep(100);
}
var output = cmdRun.StdOut.ReadAll();
alert(output);
Now i am able to get the output in variable output.
现在我能够在变量输出中获得输出。
My problem is using Run method i can hide the commandprompt(by passing parameters WshShell.Run(launch,0,true)) Where as by using Exec method i am not able to hide the commandprompt. I want this commandprompt to be hidden.
我的问题是使用 Run 方法我可以隐藏命令提示符(通过传递参数 WshShell.Run(launch,0,true)) 而通过使用 Exec 方法我无法隐藏命令提示符。我想隐藏这个命令提示符。
Can you please help me in this regard? Thanks
你能在这方面帮助我吗?谢谢
回答by Panayot Karabakalov
Yes, that bother all wsh scripters. No way to hide wshExec
object, only .Run
allow this option, but no StdOut
in this case. Shortly, the only way is to redirect your output to file.
是的,这困扰着所有 wsh 脚本编写者。无法隐藏wshExec
对象,只.Run
允许此选项,但StdOut
在这种情况下不允许。很快,唯一的方法就是将您的输出重定向到文件。
WshShell = new ActiveXObject("WScript.Shell");
var launch ="cmd.exe /c java -classpath . HelloWorld > output.txt";
var cmdRun = WshShell.Run(launch,0,true);