pythonnode.jspython-2.7python-3.xwsadmin

What would be the best way to call shell script or python from Node JS?


My use case is, I am building a web portal with Angular , Node and MongoDB, and now I have to call python which in turn runs some wsadmin commands.

Usage of this portal is not gonna be heavy. All these runs on same Solaris host .

Appreciate your response...


Solution

  • Use child_process.exec

    For example:

    var exec = require('child_process').exec,
        child;
    
    child = exec('python test.py',
      function (error, stdout, stderr) {
        console.log('stdout: ' + stdout);
        console.log('stderr: ' + stderr);
        if (error !== null) {
          console.log('exec error: ' + error);
        }
    });