首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >从Node.js执行Powershell脚本

从Node.js执行Powershell脚本
EN

Stack Overflow用户
提问于 2012-04-17 01:54:52
回答 4查看 72.8K关注 0票数 44

我在网上和Stackoverflow上找了很久,但没有找到这个问题的答案。您将如何从Node.js执行Powershell脚本?该脚本与Node.js实例位于同一服务器上。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-04-17 04:49:01

您可以只生成一个子进程"powershell.exe“,并监听stdout命令输出和stderr错误:

代码语言:javascript
复制
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
票数 82
EN

Stack Overflow用户

发布于 2020-04-15 09:24:27

做这件事的新方法

代码语言:javascript
复制
const { exec } = require('child_process');
exec('command here', {'shell':'powershell.exe'}, (error, stdout, stderr)=> {
    // do whatever with stdout
})
票数 22
EN

Stack Overflow用户

发布于 2014-07-10 00:29:21

除了公认的答案之外,还有一个名为Edge.js的Node.JS库,它允许在节点内执行各种语言。包括C#,J#,.Net,SQL,Python,PowerShell和其他CLR语言。

请注意,Edge.js需要Windows3.0&只能在PowerShell上运行(许多其他功能也可以在Mac和Linux上运行)。

票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10179114

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档