Is it possible to asynchronously call JavaScript functions in Windows Script Host?

Imagine you have a simple function in a Windows Script Host (JScript) environment:

function say(text) {
    WScript.Sleep(5000);
    WScript.Echo(text);
}

Is it possible to call asynchronously say()?

Note. Browser-based methods such as setInterval()or setTimeoutare not available in WSH.

+3
source share
2 answers

No, Windows Script Host does not support Script calls asynchronously. To achieve this effect, you will have to run two scripts at the same time:

// [main.js]
var oShell = new ActiveXObject("WScript.Shell");
oShell.Run(WScript.FullName + " say.js Hello");

WScript.Echo("Hello from main");

 

// [say.js]
WScript.Sleep(5000);
WScript.Echo(WScript.Arguments.Item(0));
+2
source

, setTimeout/setInterval Windows Script Host (). , , SO, . , ( "TJ", ) , . . , .

+1

Source: https://habr.com/ru/post/1780219/


All Articles