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.
October 17, 2006
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"
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
You May Also Like