Forum Moderators: open
So yes, can JavaScript write to an external file?
Can it call external programs? i.e. program.exe
Thanks to the kind person that lets me know whether it can do it!
Duncs
can JavaScript write to an external file?
The short answer is no - for security reasons, JavaScript is not allowed to write or read files on the client machine.
Can it call external programs? i.e. program.exe
Short answer is no, again for the same reasons as above. However, in an internal, controlled environment there is a way (it exploits an old IE security bug. Pre 5.5 SP2 I think):
<head>
<HTA:APPLICATION ID="AppRunner"
APPLICATIONNAME="AppRunner"
WINDOWSTATE="normal">
<script language=JScript>function runApp()
{
var wshShell = new ActiveXObject("WScript.Shell");
wshShell.Run("file:///PATH/TO/WHATEVER.EXE", 1, true);
}</script>
</head>
This should not be used in anything but a controlled, intranet type environment.
HTH
For example:-
widget://launch&commandlineoptions=nil
Would then appear as a hyperlink in the users browser. You can also then supply command lines to the app depending on the link text. That link would trigger whatever application you associated with the "widget" protocol.
Windows namespace and messing with it is complex though. It also alienates linux users...... (and Mac of course).
TJ
Thanks for the reply.
Basically what you are saying is JavScript wont be able to do what i want. Thats useful to know! So...
What language would you advise me to learn? What i want to do is to take inputs from an HTML form and use them to run a .exe file. Normally this runs of a data file,..such as "paramater.dat", where the inputs are listed. SO basically i need to write the inputs to this file...
So what i think i need to do is:
#take the inputs (checked with JavaScript) and write them into a temporary file.
#run the .exe telling it to look in the temporary file for its inputs
#run the program. May take a while (30mins+)
#take the output file and email it to the email address supplied by the online user.
Any advice on what i need to write/learn to perform this?! It needs to all happen when the HTML form is submitted.
Thanks,
Dunc
The main problem is that you're trying to do something that browsers expressly try to prevent - local access to data and programs - for the very good reason that such functionality would allow a web page to do *anything* to your PC.
In a controlled (trusted) environment like a managed corporate network you may be able to configure user PCs to allow this type of functionality.
A better solution imho would be to keep everything web based (i.e. run the .exe/equivalent code as part of a server-side program) where all the user has to do is interact with normal web pages and forms displayed in their browser.
Thanks for the reply.
A better solution would be to keep everything web based (i.e. run the .exe/equivalent code as part of a server-side program) where all the user has to do is interact with normal web pages and forms displayed in their browser.
Yes, this sounds like a good idea. I have been looking at that side of things as well. What sort of server side scripting would you recommend?!
JavaScript (would be the easiest for me) doesn't allow file/executable interaction.
What about php/perl?!
I am on a Unix network, do you need to install things for php & perl, or should your average browser pick em up like most browsers pick up JavaScript?
Thanks,
Duncs
All the server-side scripting languages do the same thing, so you can choose whatever is most suitable for your expertise and environment - assuming your web host supports it!
ASP pages can be written in Javascript, and if the server is running Windows it could run the .exe program, however this may run into scaleability problems (multiple .exe's running at the same time could confuse and lockup the server).
Since you are Unix-based, you may find php or perl more suitable. You would need to breakdown what the code in the .exe is doing and write your php/perl/whatever to do the equivalent processing, using html forms for user input. HTH.