gpt4 book ai didi

node.js - 为什么 Node.js 忽略我的 PowerShell ExecutionPolicy 设置?

转载 作者:太空宇宙 更新时间:2023-11-04 01:08:56 34 4
gpt4 key购买 nike

我有一个Node.js我试图调用的应用程序 PowerShell :

var app = require('express')(),
child_process = require('child_process');

app.post('/deploy', function(req, res) {

var errors = '';
var child = child_process.spawn('powershell.exe', ['deploy.ps1']);

child.stderr.on('data', function(data) {
errors += data;
});

child.stderr.on('end', function() {
if (errors) {
console.log('Error:');
console.log(errors);
}
})

child.on('exit', function(code) {
console.log('Powershell Script finished');
if (!!code)
console.log('I think it failed');
else
console.log('I think it worked.')
});

child.stdin.end();

res.end('');
});

app.listen(3000);
console.log('Listening on port 3000');

当我运行它时(无论 .ps1 文件是否存在),我得到以下信息:

File C:\Users\jkodroff.INTERNAL.000\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded because
the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:2
+ . <<<< 'C:\Users\jkodroff.INTERNAL.000\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException

File C:\Users\jkodroff.INTERNAL.000\Code\gitpulldeploy.js\deploy.ps1 cannot be loaded because the execution of scripts is
disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:13
+ .\deploy.ps1 <<<<
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException

我已经验证 get-executionpolicy 返回 unrestricted,那么什么给出了?

奖励问题一旦我在IIS中托管此流程,我将如何解决同样的问题?

更新这不起作用:var child = child_process.spawn('powershell.exe', ['-ExecutionPolicybypass', '.\\deploy.ps1']);

这也不是:将 C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe 中的执行策略设置为 unrestricted,然后执行var child = child_process.spawn('powershell.exe', ['.\\deploy.ps1']);

但是这确实在命令行上有效:powershell -ExecutionPolicy 绕过 .\deploy.ps1

最佳答案

听起来您正尝试在与将执行策略设置为无限制的环境不同的执行环境 (x86/x64) 中运行 PowerShell 脚本。

简单的修复方法是将-ExecutionPolicy Bypass 添加到PowerShell 命令行。这将绕过执行策略并执行脚本。

关于node.js - 为什么 Node.js 忽略我的 PowerShell ExecutionPolicy 设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19966086/

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