How can I run a local Windows Application and have

2019-04-07 14:53发布

问题:

I have Windows Application (.EXE file is written in C and built with MS-Visual Studio), that outputs ASCII text to stdout. I’m looking to enhance the ASCII text to include limited HTML with a few links. I’d like to invoke this application (.EXE File) and take the output of that application and pipe it into a Browser. This is not a one time thing, each new web page would be another run of the Local Application!

The HTML/java-script application below has worked for me to execute the application, but the output has gone into a DOS Box windows and not to pipe it into the Browser. I’d like to update this HTML Application to enable the Browser to capture that text (that is enhanced with HTML) and display it with the browser.

<body>
 <script>
 function go() {
   w = new ActiveXObject("WScript.Shell");
   w.run('C:/DL/Browser/mk_html.exe');
   return true;
   }

 </script>

 <form>
   Run My Application (Window with explorer only)
     <input type="button" value="Go" 
     onClick="return go()">
</FORM>

</body>

回答1:

  1. Have the executable listen on a port following the HTTP protocol.
  2. Then have the web page make AJAX-style HTTP requests to the local port with JAvascript.
  3. The executable returns text.
  4. The web page updates itself through DOM manipulation in Javascript.

Yes, this works. It is happening 5 feet away from me right now in another cubicle.



回答2:

This is called CGI



回答3:

Your already using WScript to launch, it can also read StdOut.

<html>
<head>
<script type="text/javascript">
function foo() {
 var WshShell = new ActiveXObject("WScript.Shell");
 var oExec = WshShell.Exec("ipconfig.exe");
 var input = "";

 while (!oExec.StdOut.AtEndOfStream) {
         input += oExec.StdOut.ReadLine() + "<br />";
 }

 if (input)
  document.getElementById("plop").innerHTML = input;
}
</script>
</head>
<body onload="foo();">
 <code id="plop"></code>
</body>
</html>


回答4:

It would be easier to have your EXE create a temp file containing the HTML, then just tell Windows to open the temp HTML file in the browser.