Task
Execute a system command and get its output into the program. The output may be stored in any kind of collection (array, list, etc.).




Related task
  Execute a system command


For Each line In ExecCmd("ipconfig /all")
    Wscript.Echo line
Next
 
'Execute the given command and return the output in a text array.
Function ExecCmd(cmd)
 
    'Execute the command
    Dim wso : Set wso = CreateObject("Wscript.Shell")
    Dim exec : Set exec = wso.Exec(cmd)
    Dim res : res = ""
 
    'Read all result text from standard output
    Do
        res = res & VbLf & exec.StdOut.ReadLine
    Loop Until exec.StdOut.AtEndOfStream
 
    'Return as a text array
    ExecCmd = Split(Mid(res,2),vbLf)
End Function