使用javascript从jar文件中获取返回值

时间:2013-05-07 04:04:26

标签: javascript

我学会了在javascript中使用ActiveXObject Object运行一个jar文件。 现在,我需要从jar文件中获取返回值。我不能使用'applet'因为项目要求。

这是简单的编码......

function RunExe(){  
     w = new ActiveXObject("WScript.Shell");  
     w.run('C://WindowJar.jar');
     return true;
}

如何从jar文件中获取不使用'applet'的返回值。

谢谢你的建议。

1 个答案:

答案 0 :(得分:0)

我认为唯一可行的方法是使用函数 System.out.println 从jar中打印'返回值'。 所以你可以使用下面的代码在javascript中读取这个输出:

function RunExe(){  
     w = new ActiveXObject("WScript.Shell");  
     var ex =w.Exec('C://WindowJar.jar');
     var ret = "";
     //read the output of the jar
     while (!ex.StdOut.AtEndOfStream) {
         ret += ex.StdOut.ReadLine();
     }
     //alert the output
     alert(ret)
     return true;
}

此答案基于此问题How can I run a local Windows Application and have the output be piped into the Browser