SitePoint Sponsor

User Tag List

Results 1 to 25 of 25

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    SitePoint Enthusiast Adam Chrapkowski's Avatar
    Join Date
    Sep 2011
    Location
    Poland
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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/an...erpreter-linux.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by javascripter View Post
    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.
    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?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    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?

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by javascripter View Post
    Ok, is there a non browser solution?
    Well Rhino and Spidermonkey are the two most popular non-browser ways of developing JavaScript.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,807
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by javascripter View Post
    hehe, ok. But i guess there should some way to atleast a run a shell command, since windows and IE have activeobject.
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Adam Chrapkowski View Post
    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/an...erpreter-linux.
    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.

    2. 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.

  9. #9
    SitePoint Evangelist smftre's Avatar
    Join Date
    Dec 2008
    Location
    London
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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".
    Statvoo.com The Website Traffic Monitor
    The best way to monitor traffic to your sites for free!


    Web Development London UK We make web 3.0 applications

  10. #10
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by smftre View Post
    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.

  11. #11
    SitePoint Evangelist smftre's Avatar
    Join Date
    Dec 2008
    Location
    London
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Statvoo.com The Website Traffic Monitor
    The best way to monitor traffic to your sites for free!


    Web Development London UK We make web 3.0 applications

  12. #12
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...

  13. #13
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by javascripter View Post
    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's most likely to be the operating system itself asking you how to deal with an unknown file type.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  14. #14
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    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. Screen shot 2011-10-03 at 6.11.55 PM.jpg

    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!!

  15. #15
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by javascripter View Post
    So the option might have come from the server side code
    It's definitely server-side header setting that control that.

    "Content-Disposition: attachment; ..."

    Quote Originally Posted by javascripter View Post
    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?
    How? As in, how is the browser able to have the permission to run the file?

    Quote Originally Posted by javascripter View Post
    And one more thing, if i select do this automatically for following files then all my files will be executed w/o asking!!
    That's right, because you selected to "do this automatically" for that particular type of download.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  16. #16
    SitePoint Evangelist smftre's Avatar
    Join Date
    Dec 2008
    Location
    London
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is because that file type is not recognized by the OS and it asks you what it should do with it.
    Statvoo.com The Website Traffic Monitor
    The best way to monitor traffic to your sites for free!


    Web Development London UK We make web 3.0 applications


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •