• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 589
  • Last Modified:

Reading stdout from the Windows script host object

Nothing is returning from the .read call ??
Any ideas on why this isn't working and what I should do to enable it??

Private Sub Command1_Click()

    Dim objwsh As New WshShell
    Dim sInput As String

    Set objWSHexec = objwsh.Exec("ipconfig")

    While Not objWSHexec.StdOut.AtEndOfStream
          sInput = sInput & objWSHexec.StdOut.Read(1)
         If InStr(sInput, "Press any key") <> 0 Then
            Exit Sub
         End If
    Wend
   
End Sub
0
mccainz2
Asked:
mccainz2
  • 2
1 Solution
 
EDDYKTCommented:
Try this

Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("%comspec% /c ipconfig.exe")

Do Until objExecObject.StdOut.AtEndOfStream
    strLine = objExecObject.StdOut.ReadLine()
    strIP = Instr(strLine,"Address")
    If strIP <> 0 Then
        Wscript.Echo strLine
    End If
Loop


From http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/scrguide/sas_wsh_pkoy.asp
0
 
mccainz2Author Commented:
Excellent Eddy! what is the purpose of comspec ????

Final code , only trivial modifications needed....

Private Sub Command2_Click()

    Dim Wscript As New WshShell
   
    Set objShell = New WshShell
    Set objExecObject = objShell.Exec("%comspec% /c ipconfig.exe")

    Do Until objExecObject.StdOut.AtEndOfStream
        strline = objExecObject.StdOut.ReadLine()
        Debug.Print strline
        strIP = InStr(strline, "Address")
    Loop

End Sub
0
 
EDDYKTCommented:
In WindowNT or high %comspec% returns cmd.exe
In Win95 or higher %comspec% returns command.exe
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now