我正在尝试使用SystemWorker
Wakanda 服务器端 API 来实现一些目标。但我无法实现它。我确定我在SystemWorker
.
我想从 Windows 启动 PowerShell,然后在里面运行两个命令。要手动执行此操作,我只需powershell
在cmd.exe中运行,然后我就可以开始编写 PowerShell 命令并取回我的数据。
在 Wakanda,我使用该代码设置了一个ssjs文件:
var powershell = new SystemWorker(['powershell'],null);
powershell.postMessage('Add-Type -AssemblyName "PresentationCore"');
powershell.endOfInput();
powershell.postMessage('[Windows.Media.Fonts]::SystemFontFamilies');
powershell.endOfInput();
powershell.onmessage = function (event) {
var data = event.data;
debugger;
};
powershell.onerror = function (event) {
debugger;
};
powershell.onterminated = function (event) {
// potentially check event.exitStatus or event.forced
debugger;
exitWait();
};
wait();
我还有一个包含以下内容的systemWorkers.json文件:
[
{
"name" : "powershell",
"executable" :
[
{ "path" : "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" }
]
}
]
我只想执行这两个命令Add-Type -AssemblyName "PresentationCore"
,并[Windows.Media.Fonts]::SystemFontFamilies
在我的 PowerShell 中获取机器上所有可用字体的列表。
如果我查看任务管理器,则会启动 PowerShell,但我从未实现执行我的两个命令行或取回数据。我只能在onterminated
回调中结束。
我错过了什么?