javascript - Complexe child_process not working with Promise bluebird -


i wan't execute shell command using child_process node.js https://nodejs.org/api/child_process.html, doing electron program using react js.

i want promise bluebird, function works small command 'ls' if want execute simple hello world program in folder want : cd localbuild/login/ && java main. it's working on terminal. when tried in function have error : promise rejected: error: spawn cd localbuild/login/ enoent closing code: -2.

here function :

_compile(command){      var promise = require('bluebird');     var exec = require('child_process').execfile;      var pathfile = "cd localbuild/login/";      function promisefromchildprocess(child) {       return new promise(function (resolve, reject) {         child.addlistener("error", reject);         child.addlistener("exit", resolve);       });     }     var child = exec(pathfile+ " && "+command);      //var child = exec('ls'); // works      promisefromchildprocess(child).then(function (result) {       console.log('promise complete: ' + result);     }, function (err) {       console.log('promise rejected: ' + err);     });      child.stdout.on('data', function (data) {       console.log('stdout: ' + data);     });     child.stderr.on('data', function (data) {       console.log('stdout: ' + data);     });     child.on('close', function (code) {       console.log('closing code: ' + code);     }); } 

can me please ?

the function of child_process library importing execfile, use run shell command , not run executable file.

just change :

var exec = require('child_process').execfile; 

to:

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

and should work!


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -