Results 1 to 5 of 5

Thread: terminal commands in javascript

  1. #1
    Join Date
    Nov 2009
    Beans
    195
    Distro
    Ubuntu 12.04 Precise Pangolin

    terminal commands in javascript

    I have a javascript page that I would like to use to run terminal commands and possibly show the output from those commands on that page. Google was very unhelpful as I don't think it could understand what I wanted. Specifically I would like to use the cat command to read a file, I can do this in a .sh file with $(cat /home/file) and I would like to do something similar except with javascript on my page. Ideas?

  2. #2
    Join Date
    Jul 2012
    Location
    Scotland
    Beans
    262
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: terminal commands in javascript

    I'm not sure if this is possible. You can, if you so wish, do it with PHP, but you cannot execute system commands from Javascript.

    Even if you could, I wouldn't recommend it, as its terribly unsafe, and opens up your system, creating a massive security hole
    Join us on irc at #ubuntuforums. For web chat see here

    To teach is to learn. ~ Japanese Proverb

  3. #3
    Join Date
    Nov 2009
    Beans
    195
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: terminal commands in javascript

    The page is password protected so I don't believe it would be a security problem

  4. #4
    Join Date
    Nov 2009
    Beans
    195
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: terminal commands in javascript

    How about just reading the contents of a .txt file into one of the javascript commands? I think I could figure it out from there. (Again it would be similar to using $(cat /home/file.txt) to pass the contents of that file to a variable in a .sh script)

  5. #5
    Join Date
    Feb 2005
    Location
    Melbourne, Australia
    Beans
    13,452
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: terminal commands in javascript

    Quote Originally Posted by msammels View Post
    I'm not sure if this is possible. You can, if you so wish, do it with PHP, but you cannot execute system commands from Javascript.

    Even if you could, I wouldn't recommend it, as its terribly unsafe, and opens up your system, creating a massive security hole
    100% correct, Javascript is a set of limited capability commands that specifically do not spawn off into commands that could do whoever knows what.

    If you want stupid capabilities that could possibly wreck systems then I suggest people look at the various Microsoft products.
    Regards, David.
    Please use the Forum search and Wiki search for immediate help
    Please mark your thread as Solved when appropriate.
    New to technical forums?: How To Ask Questions The Smart Way

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
  •