Is there a way to do non-blocking IO in VBS or a way to notify it of a COM event?

I have a script option that comes with Windows Media Encoder. I run it through WSH and configure the STDIN, STDOUT, and STDERR channels for it.

The script starts the encoding and, in the end, waits in a DO loop, checking the status of the encoding object so that the script knows to exit if the encoding stops. (inside the loop just prints a period and sleeps about 2 seconds).

To cleanly exit, I would like to signal a script to stop coding, which will allow it to drop the loop and clear.

I do not (or definitely want) to have a COM object implemented in our application that runs a script - otherwise I would just raise an event. (I will change my mind if it will be easier than I think in C ++)

I thought about just sending it to the character via STDIN to exit, but the problem is that all methods are for the WScript.stdin block. Is there any non-blocking way of reading with stdin or checking characters in some way?

Is it possible to make a stream in VBS? as far as I can tell, you can only perform other processes.

+3
source share
1 answer

VBS is single-threaded and there are no non-blocking calls in the WScript object.

The classic VBS kludge for an asynchronous loop signal should use a file system object. Your calling process and VBScript must agree on the location of the folder that will be controlled (let's call it c: \ temp for now).

During initialization, your script does: -

 Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")

In the loop, your code: -

 If fso.FileExists("c:\temp\signal.dat") Then
     fso.DeleteFile "c:\temp\signal.dat" 
     '' // Tidy up and exit loop
 End If

"c:\temp\signal.dat", script.

, .

+2

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


All Articles