Hul*_*ien 5 javascript shell shellexecute node.js angularjs
我需要使用 Angular JS 单击按钮来执行 shell 脚本,谁能告诉我如何实现?
在执行之前,我需要从 GUI/UI 向该 shell 脚本传递一些输入(参数、参数)。
这可以使用 node.js 来完成。在 nodejs 中创建一个休息端点并从 angular.Say 调用相同的端点:
$http.get(URL + "/script").then(function (req,response) {
...
write your code here
...
}
Run Code Online (Sandbox Code Playgroud)
在 Node.js 中使用以下代码片段。
var sys=require('util');
var exec=require('child_process').sys;
var child;
Run Code Online (Sandbox Code Playgroud)
//静止终点
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);
}
});
}
Run Code Online (Sandbox Code Playgroud)