Q. How can a Vbscript process each line in the STDOUT generated from a CMD command or batch?

Jerold Schulman

October 17, 2006

1 Min Read
ITPro Today logo in a gray background | ITPro Today

The following script is an example of how a Vbscript can process each line in the STDOUT generated by a CMD.EXE command or batch.

To run the Example.vbs script, type:

cscript //nologo FolderExample.vbs "command or batch"

Examples

cscript //nologo c:utilExample.vbs "dir /b /ad"

cscript //nologo c:utilExample.vbs "c:utiltest.bat Jerry"

Example.vbs contains:

Dim objArgumentsSet objShell = WScript.CreateObject("WScript.Shell")Set objArguments = Wscript.ArgumentsSet objShell = WScript.CreateObject("WScript.Shell")Set objExecObject = objShell.Exec("cmd /c " & objArguments(0))Do While Not objExecObject.StdOut.AtEndOfStream    strText = objExecObject.StdOut.ReadLine()' Test or display strText    Wscript.Echo strText    Loop


Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like