HulkSapien
HulkSapien

Reputation: 167

Need to execute a Shell Script from Angular JS UI

I need to execute a shell script on click of a button using Angular JS, can anyone tell me how can this be achieved ?

I need to pass a few inputs(Parameters,Arguments) to that shell script before executing,from GUI/UI.

Upvotes: 6

Views: 8494

Answers (1)

nilakantha singh deo
nilakantha singh deo

Reputation: 1006

This can be done with node.js .Make a rest end point 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;

//rest end point

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);
                      }
    });

  }

Upvotes: 0

Related Questions