Processing External Script Output in Real Time

by Jun 5, 2009

In a previous tip, you learned how to call an external VBScript from PowerShell and read back any text VBScript returned. We will now take a look at the real-time processing built into PowerShell, which allows you to meld together VBScript and PowerShell and respond to a VBScript output the second it is generated. You won't need to wait for your external VBScript to complete.

In this VBScript example, it keeps asking for names until you press Cancel or enter a blank name:

answer = InputBox("Enter a name:")
if answer<>"" then WScript.Echo answer
loop while answer <> ""

As long as answer is not empty, VBScript keeps writing it to WScript.Echo.

When PowerShell calls this script using cscript.exe, the PowerShell pipeline keeps processing the names returned by VBScript until the VBScript is canceled:

cscript.exe c:path_to_your_VBScript |
Foreach-Object { "processing '$_'…" }

You should take note of how PowerShell outputs a "processing…" message each time you enter a new name in your VBScript.