6

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.

HulkSapien
  • 157
  • 2
  • 9
  • Is the shell script located on the server hosting the webpage or is the script located on the clients machine? – heldt Oct 27 '14 at 07:40
  • 1
    The you would call an API via AJAX that would broker the execution of the script for you and return the output – Coldstar Oct 28 '14 at 08:30

1 Answers1

0

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

  }