Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 需要从AngularJSUI执行Shell脚本_Javascript_Angularjs_Node.js_Shell_Shellexecute - Fatal编程技术网

Javascript 需要从AngularJSUI执行Shell脚本

Javascript 需要从AngularJSUI执行Shell脚本,javascript,angularjs,node.js,shell,shellexecute,Javascript,Angularjs,Node.js,Shell,Shellexecute,我需要使用Angular JS在点击按钮时执行一个shell脚本,有人能告诉我如何实现吗 在执行之前,我需要从GUI/UI向shell脚本传递一些输入(参数、参数) 这可以通过node.js完成。在nodejs中创建一个rest端点,并从angular调用它。比如: $http.get(URL + "/script").then(function (req,response) { ... write your code here ... } 在node.js中,使用以下代码段 var

我需要使用Angular JS在点击按钮时执行一个shell脚本,有人能告诉我如何实现吗


在执行之前,我需要从GUI/UI向shell脚本传递一些输入(参数、参数)

这可以通过node.js完成。在nodejs中创建一个rest端点,并从angular调用它。比如:

$http.get(URL + "/script").then(function (req,response) {
...
write your code here
...    
}
在node.js中,使用以下代码段

var sys=require('util');
var exec=require('child_process').sys;
var child;
//静止终点

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

  }

shell脚本是位于托管网页的服务器上还是位于客户端计算机上?您可以通过AJAX调用API,代理脚本的执行并返回输出