想要使用WshShell.Exec方法隐藏命令提示符窗口 [英] Want to hide command prompt window in using WshShell.Exec method

查看:485
本文介绍了想要使用WshShell.Exec方法隐藏命令提示符窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从javascript执行一个java程序并希望得到输出。

I want to execute a java program from a javascript and want to get the output.

Intailly我尝试使用以下代码:

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

通过Run方法我无法获得该类的输出。

Through Run method i am not able get the output of the class.

然后我尝试使用以下代码:

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.

我的问题是使用Run方法我可以隐藏命令提示(通过传递参数WshShell.Run(launch,0,true))
在哪里使用Exec方法我无法隐藏命令提示。我希望隐藏此命令提示。

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.

在这方面你能帮我吗?
谢谢

Can you please help me in this regard? Thanks

推荐答案

是的,这会困扰所有wsh脚本编写者。无法隐藏 wshExec 对象,只有 .Run 允许此选项,但没有 StdOut 在这种情况下。不久,唯一的方法是将输出重定向到文件。

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.

WshShell   = new ActiveXObject("WScript.Shell");
var launch ="cmd.exe /c java -classpath . HelloWorld > output.txt";
var cmdRun = WshShell.Run(launch,0,true);

这篇关于想要使用WshShell.Exec方法隐藏命令提示符窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆