SitePoint Sponsor

User Tag List

Results 1 to 25 of 25
  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,701
    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,701
    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
    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.

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    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="^$">

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

  14. #14
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,701
    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

  15. #15
    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!!

  16. #16
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,701
    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

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

  18. #18
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by javascripter View Post
    How come the browser wait for the download to complete and then execute it.
    The browser doesn't run the file - the operating system does. Only the operating system can tell when the file has finished downloading.
    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="^$">

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

  20. #20
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,701
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by javascripter View Post
    Ok so is there a way through javascript where i can sense the starting of download
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  21. #21
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    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.
    Ok, then how can i sense the starting of download?

  22. #22
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,701
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by javascripter View Post
    Ok, then how can i sense the starting of download?
    Here is how events work in the web browser.
    http://www.w3.org/TR/DOM-Level-3-Eve...t-architecture

    There are no events that relate to downloading, or even files, so it is not possible for JavaScript to sense any kind of event relating to downloading.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  23. #23
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    Here is how events work in the web browser.
    http://www.w3.org/TR/DOM-Level-3-Eve...t-architecture

    There are no events that relate to downloading, or even files, so it is not possible for JavaScript to sense any kind of event relating to downloading.
    Hmmm, i understand. Is there a way through extensions, addons, like that??
    Call me troublesome, But i don wanna give up, i just wanna find when and what file is downloading on my clients browser.

  24. #24
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,701
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by javascripter View Post
    Hmmm, i understand. Is there a way through extensions, addons, like that??
    Call me troublesome, But i don wanna give up, i just wanna find when and what file is downloading on my clients browser.
    About the only way that comes to mind is for the client to send an ajax request to the PHP script that is providing the download, so that PHP can then respond when the download is complete.

    The PHP forum would know how PHP can achieve that.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  25. #25
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    About the only way that comes to mind is for the client to send an ajax request to the PHP script that is providing the download, so that PHP can then respond when the download is complete.

    The PHP forum would know how PHP can achieve that.
    Well, yeah Php can do this i know. But i really don't have server side work here. All i got is the browser. i want to do it through injecting scripts, extensions, plugins. This is for a general solution for the browser not for a particular site. I will check if there is any API in FF, Safari, Chrome extensions development for monitoring the activity status.

    But u guys where really helpful. Amazing responses, thanks a lot!!!


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
  •