Welcome to WebmasterWorld Guest from 3.227.2.109

Forum Moderators: open

Message Too Old, No Replies

Real n00b question...

Can JavaScript call an external local program?

     
11:31 am on Dec 8, 2003 (gmt 0)

New User

10+ Year Member

joined:Dec 1, 2003
posts:19
votes: 0


I have two questions really. They may appear very simple, but i am trying to find out whether this Language can do things before learning it, so as to choose which to learn. If ya see what i mean...

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

1:34 pm on Dec 8, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member blobfisk is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 25, 2002
posts:3185
votes: 0



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

1:44 pm on Dec 8, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member trillianjedi is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 15, 2003
posts:7256
votes: 3


If you wish to launch from a website an application which you have developed then you can have the installer for the app. add itself to the windows namespace, allowing you to create your own protocol.

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

1:52 pm on Dec 8, 2003 (gmt 0)

New User

10+ Year Member

joined:Dec 1, 2003
posts:19
votes: 0


Hello guys,

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

2:13 pm on Dec 8, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 29, 2002
posts:981
votes: 1


I suspect you will have problems doing this.

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.

2:20 pm on Dec 8, 2003 (gmt 0)

New User

10+ Year Member

joined:Dec 1, 2003
posts:19
votes: 0


Hey Mattur,

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

4:11 pm on Dec 8, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 29, 2002
posts:981
votes: 1


php/perl and other server-side scripting just return normal html to the browser, so nothing special is required on the client browser. To the browser these dynamic pages are just like any other page, the only difference being the html was generated dynamically on the server before being sent to the browser.

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.

11:17 pm on Dec 8, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 21, 2002
posts:977
votes: 0


If you ever need to interact with files on the user's computer, AND you only need it to work in a controlled trusted environment (such as a corporate network), you can use an ActiveX control or Java applet embedded within an HTML page.