You need to execute a Script shell from Angular JS UI

I need to execute a shell script by pressing a button using Angular JS, can someone tell me how this can be achieved?

I need to pass multiple inputs (Parameters, Arguments) to this shell script before execution, from the GUI / UI.

+4
source share
1 answer

This can be done using node.js. Create a resting endpoint in nodejs and call the same from angular.Say:

$http.get(URL + "/script").then(function (req,response) {
...
write your code here
...    
}

In node.js, use the following code snippets.

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

// end point of rest

app.get('/script', function (req, res) {

child = exec("pwd", function (error, stdout, stderr) {
      sys.print('stdout: ' + stdout);
      sys.print('stderr: ' + stderr);
      if (error !== null) {
         console.log('exec error: ' + error);
                      }
    });

  }
0
source

All Articles