簡體   English   中英

使用node.js child_process.spawn()時找不到PowerShell管理單元

[英]PowerShell snapins not found when using node.js child_process.spawn()

我正在嘗試從node.js調用PowerShell腳本。 ps腳本可以正常工作,但是當我從node.js子進程運行它時,找不到SQL管理單元。

這是node.js腳本:

"use strict";

var spawn = require('child_process').spawn;

var child = spawn('powershell.exe', ['.\\test.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();

這是PowerShell腳本(test.ps1,這是一個精簡的腳本,僅顯示錯誤):

Add-PSSnapin SqlServerCmdletSnapin100

當我從cmd窗口或PS窗口運行test.ps1時,沒有錯誤。 當我運行node.js代碼時,我得到:

Add-PSSnapin : The Windows PowerShell snap-in 'SqlServerCmdletSnapin100' 
is not installed on this machine.

我想念什么?

這是由於使用32位版本的node.js引起的。 通過安裝64位版本,此問題已解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM