gpt4 book ai didi

javascript - 在 Node js中使用回调函数执行powershell脚本

转载 作者:行者123 更新时间:2023-11-30 06:25:09 27 4
gpt4 key购买 nike

我写了一个 Node JS 脚本,应该使用 PowerShell 命令行执行。然后将 PowerShell 响应返回给 angularjs。 PowerShell 命令执行时间超过 5 分钟。所以 Node 正在向 angularjs 发送一个空响应。为此,我尝试了回调函数。但我得到了同样的空洞回应。请帮我解决这个问题。

这是在node js中使用回调函数执行powershell的代码

let ps = new shell({
executionPolicy: 'Bypass',
noProfile: true
});

function getData(callback){
ps.addCommand('C:/Users/sowmi096/Desktop/Code/jobid.ps1',a)
ps.invoke()
.then(output => {
return callback(null,output);
})
.catch(err => {
return callback(null,err);
ps.dispose();
});
}
getData(function onGetData(err,data){
if(err)
res.send(err);
res.send(data);
});

最佳答案

这里问了一个非常相似的问题:

Execute Powershell script from Node.js

那里有人建议 Edge.js图书馆。它允许从 Node.js 中执行各种语言。包括 C#、J#、.Net、SQL、Python、PowerShell 和其他 CLR 语言。请注意,Edge.js 需要 PowerShell 3.0 且仅适用于 Windows,但许多其他功能也适用于 Mac 和 Linux。

那里还有 Javier Castro 的代码示例,它从 Powershell 返回结果。

关于javascript - 在 Node js中使用回调函数执行powershell脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50967442/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com