node.js - 从节点 js 执行 Powershell 脚本失败
问题描述
我有一个我们为系统管理开发的 Powershell 脚本列表。这些脚本是使用“child_process”模块从 Node JS 应用程序调用/执行的。在我的笔记本电脑上一切正常。将 Node JS 应用程序传输到 Centos7 服务器后,我收到如下错误:
The term 'Connect-VIServer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
我检查了 Powershell 执行策略 - 一切都设置为Unrestricted
. 以用户身份 ssh 到服务器后,我可以从命令行执行相同的脚本而不会出现任何错误root
。我看到的唯一区别是 Node JS 应用程序正在使用不同的用户运行。
解决方案
发现问题 - 所有模块都安装在/root/.local/share/powershell/Modules
目录下,并且在运行 Node JS 应用程序的用户配置文件下没有安装任何内容。复制了应用用户目录下的所有模块,/home/ndjs/.local/share/powershell/Modules/
现在一切正常。
推荐阅读
- c++ - 具有可以是两种类型之一的数据成员的类
- python-3.x - pandas df:仅针对 B 列中唯一的行更改 A 列中的值
- angular - RxJS:从可能被多次调用的函数发出单个 API 请求
- wordpress - 如何在 Gutenberg 段落中创建自定义 DropdownMenu 按钮
- javascript - 我如何将 vanilla Js 代码转换为 vue js 代码
- c - 多个测试用例中的字符数组
- angular - 使用 ag-grid 为 cellRendererFramework 传递多个值?
- machine-learning - 如何使用过滤器方法创建管道,这些方法选择相关性高于值的结果(特征)?
- vulkan - 如何在 Vulkan 中创建一维纹理
- scrapy - 我输入了“scrapy version”,但它会触发或加载文件夹中的其他蜘蛛