I’m using JScript (which is the same as VBScript pretty much) from within an .hta file, to open a new shell command and capture its output. Here’s what I got so far after Googling a bit:
var shell = new ActiveXObject("WScript.Shell")
var e = shell.Exec("%comspec% /c ping google.com 2>&1 ")
while(!e.StdOut.AtEndofStream) {
var line = e.StdOut.ReadLine()
document.getElementById('log').value = line
}
This works. However, it’s not asynchronous. The while loop causes my .hta interface to just block (the UI becomes unusable) until the shell command finished. If I remove the while loop, the shell.Exec command doesn’t seem to block, so the issue is somewhere within the loop.
I think the blocking issue only happens because I’m within an .hta environment. It doesn’t seem to happen if I run my script through the command-line using cscript.exe
How can I avoid the blocking behavior and access the output of my command in real-time?
You probably have to fake a background thread by calling
setTimeOutrepeatedly and only doing a small amount of work in the timer callback…