Javascript in linux

Hi,
This is my first post here, hope this is just a start.

i have 3 questions.

Note : All my queries are with reagard to linux

  1. Can i create a file using javascript?

  2. can i run a shell command(linux) using javascript.

  3. I want a file to be downloaded and executed automatically. Like the RUN button in windows while downloading. How do i achieve tat.

thanks in advance.

There is no difference between Linux and Windows JavaScript.
I do not know why do you want create shell scripts with JavaScript but If you really need that look for standalone JavaScript interpreter. There is a similar question http://bytes.com/topic/javascript/answers/850094-standalone-javascript-interpreter-linux.

The answers to all three of those questions are 1. no, 2. no, and 3. can’t be done.

Are you interested in looking at non-web browser solutions instead?

hehe, ok. But i guess there should some way to atleast a run a shell command, since windows and IE have activeobject.
There should be something with FF and Linux may be?

Ok, is there a non browser solution?

I thought of doing like this in worst case. Give a force download of the file, attach a shell command to monitor the completion of the download and then execute the file? So since u say linux shell commands cant be run is there any other way?

Well Rhino and Spidermonkey are the two most popular non-browser ways of developing JavaScript.

How about using XULRunner in FF to run the script?

My initial action will be to click a link, so i cannot make it entirely non-browser. The first action event is from browser.

Okay, this seems bit complicated. Let me clear my requirement.

1: User will click a link or button, this will start a file download. This file has to be downloaded forcefully, without asking save cancel or anything like that.

  1. After downloading it should be executed autoimatically.

Can this be achieved without serever side scripting in linux OS. Here the end user who is going to click the link uses linux.

That’s the biggest security hole that Microsoft ever created. They locked it down pretty tight in IE7 so that 3/4 of what it could do in IE6 was disabled as it was too risky and Microsoft decided they couldn’t afford the millions of trillions of dollars the legal cases would cost them. It was only ever intended for use on intranets and is now locked down so as to prevent its use on the internet as much as possible. IE now disables all JavaScript run locally in the web browser by default requiring that each local file you try to run there be separately approved - simply because they couldn’t provide the necessary security any other way. Other browsers can happily run local JavaScript because it has no access outside the browser.

The browser provides the most potential security issues with running JavaScript and so JavaScript has the least functionality available to it there.

If you want to run JavaScript locally outside the browser then it is one of the three languages supported by Adobe Air and there it can read and write files. There is a version of Adobe Air for Linux just as there is one for Windows.

If you want to force such a thing to happen you should look more on the flash side of things and have a client running which will then accept the download, but this too won’t really work as flash doesn’t have access to the local filesystem due to security issues. (Air does though)
Basically, this cannot be done at all unless you actually make a client that has local filesystem permissions, and on Linux this usually means write permissions, which leads us down the root access path, which basically goes and says “your answer is no”.

Hmm so basically the RUN button in windows is a security breach!
Thanks for the inputs i will check through adobe air options for this.

It is to a degree but not really in this context as RUN being a button relies on the end user’s discretion when clicking it.
The same way as if you open an email with an attachment, it’s an executable file and you “just trust it and run it”… Probably a no-no on the paranoid-security-front as anything could contain malware. On linux it’s not as common though.

Sorry for coming back again, After our discussions i was in a mind frame that this cannot be done in linux and left it without testing.

But today i saw FF in macOS, asking for same run like option, “Open With”… How is it achieving that??
After downloading how FF is capable of firing a command or event to run that downloaded file in another application. Here its kind of linux as well…

That is because that file type is not recognized by the OS and it asks you what it should do with it.

That’s most likely to be the operating system itself asking you how to deal with an unknown file type.

It asked for zip file, which it found particularly which application to use to open it up.

I found this link which explains how to bring up that option in all browsers, so there is an option and this is through browser not OS. http://www.php.net/manual/en/function.header.php#102175

So the option might have come from the server side code, so no prob with that. But all i am interested is the second step done by the browser. When i click “open with” it downloads to temp file (fine till this) and executes the file from there (how this is done?)

How is the browser able to fire that command?

And one more thing, if i select do this automatically for following files then all my files will be executed w/o asking!!

It’s definitely server-side header setting that control that.

“Content-Disposition: attachment; …”

How? As in, how is the browser able to have the permission to run the file?

That’s right, because you selected to “do this automatically” for that particular type of download.

So surely run button in windows can be implemented in linux as well.
yes, how is the browser have the permission to execute that file.
And one more thing, How come the browser wait for the download to complete and then execute it. Since it waits is it attaching a process on the BG which polls or waits for this download to complete? If thats the case then executables will be run without warning.

The browser doesn’t run the file - the operating system does. Only the operating system can tell when the file has finished downloading.

Ok so is there a way through javascript where i can sense the starting of download and what type of file is it?
So that i can then use some plugin to give a message to OS to lookout for the completion of download(any info’s on how to check this) and then start executing it.

No, JavaScript doesn’t provide such abilities. You can ask the same type of question in many ways, but you will continue to receive the same message, that JavaScript is limited in such ways.