PowerShellを呼び出そうとするNode.jsアプリケーションがあります。
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', ['-ExecutionPolicy bypass', '.\\deploy.ps1']);
これも行いません: executionpolicy をunrestriected
inC:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
に設定してから実行します
var child = child_process.spawn('powershell.exe', ['.\\deploy.ps1']);
ただし、これはコマンドラインで機能します。
powershell -ExecutionPolicy Bypass .\deploy.ps1