2

SystemWorkerWakanda サーバー側 API で何かを達成しようとしています。しかし、私はそれを達成することはできません。のワークフローで何かが欠けていると確信していますSystemWorker

Windows から PowerShell を起動し、内部で 2 つのコマンドを実行したいと考えています。これを手動で行うに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"2 つのコマンドを[Windows.Media.Fonts]::SystemFontFamiliesPowerShell で実行して、マシンで使用可能なすべてのフォントのリストを取得したいだけです。

タスク マネージャーを調べると、PowerShell が起動されますが、2 つのコマンド ラインを実行したり、データを取得したりすることはできません。私はonterminatedコールバックにたどり着くだけです。

私は何が欠けていますか?

4

1 に答える 1

1

Finally I reach to make it work.

Now I put my command in a ps1 file that I give as an argument to my SystemWorker

So it look like this :

var powershell = new SystemWorker(['powershell "C:/Users/<MyName>/Desktop/<myScript>.ps1"'],null);

powershell.onmessage = function (event) {

};
powershell.onerror = function (event) {
};
powershell.onterminated = function (event) {
    exitWait();
};
wait();

I think is more easy to do this way so all my commands are in one file and then I just ask the System worker to execute the PowerShell and to run my script.

于 2015-06-05T10:40:06.287 に答える