m126531
m126531

Reputation: 275

Node-webkit app talk to terminal

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

Upvotes: 1

Views: 249

Answers (3)

ikaruss
ikaruss

Reputation: 491

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.

Upvotes: 0

technosaurus
technosaurus

Reputation: 7812

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.

Upvotes: 0

Sky Walker
Sky Walker

Reputation: 1018

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

Upvotes: 1

Related Questions