Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute Command from Node Webkit

I want to run a command inside of a script tag within my index.html file using node webkit. Is such a thing possible and how would the code look like if I wanted to execute the command 'pwd' for example?

Thanks in advance

like image 735
user2554585 Avatar asked Apr 27 '26 16:04

user2554585


2 Answers

Does something like this not work?

var sys = require('sys')
var exec = require('child_process').exec;
var child;

// executes `pwd`
child = exec("pwd", function (error, stdout, stderr) {
  sys.print('stdout: ' + stdout);
  sys.print('stderr: ' + stderr);
  if (error !== null) {
    console.log('exec error: ' + error);
  }
});
like image 174
tier1 Avatar answered Apr 30 '26 08:04

tier1


The documentation for node webkit states:

Complete support for Node.js APIs and all its third party modules.

Which would indicate that you could use the node childprocess api:

http://nodejs.org/api/child_process.html

like image 35
j03m Avatar answered Apr 30 '26 08:04

j03m