tags:

views:

109

answers:

2

I am trying to use html/javascript to run a local .exe file in a local browser. The .exe file will generate asci text and I have it programed to encapsulate the text in html legible to the browser. But I want to have it load the new output from the .exe in the current browser, replacing whats there now.

+1  A: 

The short answer: you can't do it without writing a browser plug-in of some sort. Probably there's a simpler way of doing what you want.

egrunin
+2  A: 

There are two solutions I can think of.

1) In IE - Use WScript.Shell and do whatever you need in Windows.

In IE - Here is a sample to open notepad. You place your executable there and then have it write it's file and then read the file.

 <script>
 function go() {
   w = new ActiveXObject("WScript.Shell");
   w.run('notepad.exe');
   return true;
   }

 </script>

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

Here is a sample for reading from a file

// define constants
// Note: if a file exists, using forWriting will set
// the contents of the file to zero before writing to
// it. 
var forReading = 1, forWriting = 2, forAppending = 8;
// define array to store lines. 
rline = new Array();
// Create the object 
fs = new ActiveXObject("Scripting.FileSystemObject");
f = fs.GetFile("test.txt");
// Open the file 
is = f.OpenAsTextStream( forReading, 0 );
// start and continue to read until we hit
// the end of the file. 
var count = 0;
while( !is.AtEndOfStream ){
   rline[count] = is.ReadLine();
   count++;
}
// Close the stream 
is.Close();
// Place the contents of the array into 
// a variable. 
var msg = "";
for(i = 0; i < rline.length; i++){
   msg += rline[i] + "\n";
}
// Give the users something to talk about. 

WScript.Echo( msg );

2) Create a signed Java Applet and talk to it through JavaScript

Maybe there is a way to talk to a Java Applet from the Javascript and then have the Applet do the work - It would probably need to be signed.

Romain Hippeau
Yes, but then he wants to load the result of that edit into the *current* browser window!
egrunin