简体   繁体   English

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

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

I am trying to call a PowerShell script from node.js. 我正在尝试从node.js调用PowerShell脚本。 The ps script works fine, but fails to find SQL snapins when I run it from a node.js child process. ps脚本可以正常工作,但是当我从node.js子进程运行它时,找不到SQL管理单元。

Here is the node.js script: 这是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();

And here is the PowerShell script (test.ps1, this is a stripped down script to just show the error): 这是PowerShell脚本(test.ps1,这是一个精简的脚本,仅显示错误):

Add-PSSnapin SqlServerCmdletSnapin100

When I run test.ps1 from a cmd window or PS window, there are no errors. 当我从cmd窗口或PS窗口运行test.ps1时,没有错误。 When I run the node.js code, I get: 当我运行node.js代码时,我得到:

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

What am I missing? 我想念什么?

This was caused by using the 32-bit version of node.js. 这是由于使用32位版本的node.js引起的。 By installing the 64-bit version, the problem was resolved. 通过安装64位版本,此问题已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM