Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  60] [ 7]  / answers: 1 / hits: 18269  / 11 Years ago, thu, february 28, 2013, 12:00:00

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 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.



Can you please help me in this regard?
Thanks


More From » javascript

 Answers
3

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

[#79945] Wednesday, February 27, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pranavrorys

Total Points: 466
Total Questions: 87
Total Answers: 115

Location: Barbados
Member since Sun, Nov 27, 2022
2 Years ago
pranavrorys questions
Fri, May 27, 22, 00:00, 2 Years ago
Thu, Oct 28, 21, 00:00, 3 Years ago
Sat, May 30, 20, 00:00, 4 Years ago
Fri, Dec 20, 19, 00:00, 5 Years ago
;