1

Is it possible for me to write html/css/javascript to have a button that'll open up the terminal program on my computer and run some scripts?

The scenario I want is: On my ubuntu laptop, run my node-webkit app, click a button on the screen, a terminal opens, and start executing some scripts.

Thanks

m126531
  • 265
  • 1
  • 3
  • 11
  • i dont think javascript can open terminal because of security policies but you can use node.js to excute javascript from command line/ terminal – Sky Walker Apr 07 '15 at 22:23
  • I'm looking for an easy way to make a GUI to execute a bunch of scripts. What would be the best way to go, that is relatively OS-independent? – m126531 Apr 07 '15 at 22:29
  • Isn't `require('child_process').exec` what you are looking for? See http://stackoverflow.com/q/19103735/1998046 – ikaruss Apr 10 '15 at 01:09

3 Answers3

1

from web page you cant do this but you can use node.js , if you want to make a GUI app with JavaScript you can use node-webkit with it you can build cross platform software that can work with Linux and execute commands in the terminal

Sky Walker
  • 978
  • 1
  • 9
  • 22
  • I'm kind of getting the hang of making a GUI app with node-webkit. However, how do I pipe information from the GUI to the local terminal? – m126531 Apr 10 '15 at 00:55
0

You can do this from a webpage, but make sure your hosts.allow (or equivalent) is set to localhost only. Just run any web server with cgi capability and drop in your cgi script that runs your scripts into the cgi-bin directory. Then just add an empty form submit button or link to localhost:8080/cgi-bin/your_script

Slitaz uses this for their entire configuration system using busybox httpd and shell scripts, but uses shell generated interactive forms instead of a terminal. See: http://hg.slitaz.org/tazpanel/file/

Another way to do it without a web server (at least with firefox/seamonkey - not tried with chrom) is to associate a file extension so that files with that extension are opened with that script. Then just make a link to an empty file with that extension.

technosaurus
  • 7,676
  • 1
  • 30
  • 52
0

Use child_process module:

<script>
  var cp = require('child_process');

  function run() {
    cp.exec('gnome-terminal -x bash -c "./your_script.sh; read -n1"');
  }
</script>

<button onclick="run()">your_script.sh</button>

You can also remove read -n1 and simply run

    cp.exec('gnome-terminal -x ./your_script.sh');

in case you don't want to wait for any key press.

ikaruss
  • 491
  • 4
  • 13