Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

As the description of Wscript:String value indicating the command line used to run the script: The command line should appear exactly as it would if you typed it at the command prompt.

I can run my java file using the command "java test http://www.bbc.co.uk/news/world-us-canada-12116778" but it is not working when I wrote the JavaScript below. Can someone can tell me why? Thank you or can tell me there is some other method to call my Java file when I open a html file?

<script type="text/javascript">
funciton {}
var WshShell = new ActiveXObject("WScript.Shell");
var oExec= WshShell.Exec(""java test http://www.bbc.co.uk/news/world-us-canada-12116778"");
while (oExec.Status == 0)
{
     WScript.Sleep(100);
}
</script>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
802 views
Welcome To Ask or Share your Answers For Others

1 Answer

Take a look at the WSHSell object's run method. The following code works for me:

var shell = new ActiveXObject("WScript.Shell");
shell.run("cmd /c java -jar MyApplication.jar");
// should work without JARs as well, take care for the working path

The run method has an option to wait for the java program to return.

Hope this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...