Code: Select all
SUB CJtest
DIM strCommand, WshShell, WshShellExec, strOutput
Const WshFinished = 1
Const WshFailed = 2
strCommand = "ping.exe 127.0.0.1"
Set WshShell = CreateObject("WScript.Shell")
Set WshShellExec = WshShell.Exec(strCommand)
On Error Resume Next
Dim line, linecount
WHILE WshShellExec.Status = 0
line = vbNullString
line = WshShellExec.StdOut.ReadLine()
If line <> vbNullString Then
strOutput = strOutput & line & vbCrLf
linecount = linecount + 1
End If
WEND
Select Case WshShellExec.Status
Case WshFinished
Do
line = WshShellExec.StdOut.ReadLine()
If line <> vbNullString Then
strOutput = strOutput & line & vbCrLf
linecount = linecount + 1
End If
Loop While Not WshShellExec.Stdout.atEndOfStream
Case WshFailed
strOutput = WshShellExec.StdErr.ReadAll
End Select
MsgBox strOutput
MsgBox linecount
END SUB
https://stackoverflow.com/questions/569 ... ing-output