1

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 をunrestriectedinC:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exeに設定してから実行します var child = child_process.spawn('powershell.exe', ['.\\deploy.ps1']);

ただし、これコマンドラインで機能します。 powershell -ExecutionPolicy Bypass .\deploy.ps1

4

1 に答える 1

1

実行ポリシーを無制限に設定した環境とは異なる実行環境 (x86/x64) で PowerShell スクリプトを実行しようとしているようです。

簡単な修正は-ExecutionPolicy Bypass、PowerShell コマンド ラインに を追加することです。これにより、実行ポリシーがバイパスされ、スクリプトが実行されます。

于 2013-11-13T22:53:15.710 に答える