最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Want to hide command prompt window in using WshShell.Exec method - Stack Overflow

programmeradmin3浏览0评论

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

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.

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 mand 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 mandprompt(by passing parameters WshShell.Run(launch,0,true)) Where as by using Exec method i am not able to hide the mandprompt. I want this mandprompt to be hidden.

Can you please help me in this regard? Thanks

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

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.

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 mand 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 mandprompt(by passing parameters WshShell.Run(launch,0,true)) Where as by using Exec method i am not able to hide the mandprompt. I want this mandprompt to be hidden.

Can you please help me in this regard? Thanks

Share Improve this question asked Feb 28, 2013 at 5:59 user2118354user2118354 631 gold badge1 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

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

I know this thread is quite old, but I just came up against the same problem and found a solution by adding "exit" to the mand string, which closes the window.

From the cmd page of Microsoft Docs:
You can specify multiple mands for [string]. Separate them by the mand separator && and enclose them in quotation marks. For example:

"[mand1]&&[mand2]&&[mand3]"

So the full mand string you pass to WshShell.Exec would look like this:

        cmd.exe /c "java -classpath . HelloWorld&&exit"
发布评论

评论列表(0)

  1. 暂无评论