简体   繁体   中英

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

从网页上您不能执行此操作,但是可以使用node.js,如果要使用JavaScript创建GUI应用程序,则可以使用node-webkit ,可以构建可与Linux一起使用的跨平台软件并在终端中执行命令

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM