我一直在浏览网络和 Stackoverflow,但没有找到这个问题的答案。您将如何从 Node.js 执行 Powershell 脚本?该脚本与 Node.js 实例位于同一服务器上。
最佳答案
您可以只生成一个子进程“powershell.exe”并监听 stdout 的命令输出和 stderr 的错误:
var spawn = require("child_process").spawn,child;
child = spawn("powershell.exe",["c:\\temp\\helloworld.ps1"]);
child.stdout.on("data",function(data){
console.log("Powershell Data: " + data);
});
child.stderr.on("data",function(data){
console.log("Powershell Errors: " + data);
});
child.on("exit",function(){
console.log("Powershell Script finished");
});
child.stdin.end(); //end input
关于node.js - 从 Node.js 执行 Powershell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10179114/