views:

76

answers:

4

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

Erik Hermansen
A: 

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.

David
A: 

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>
Alex K.
+1  A: 

This is called CGI

renick
+10. This is the proper way to do this. Writing temp files is messy, having WSH listen to StdOut feels way too hacky, and there's absolutely no reason to introduce the complexity of a web server into the executable.
josh3736