Solved

Reading stdout from the Windows script host object

Posted on 2003-12-04
3
581 Views
Last Modified: 2010-05-01
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
Comment
Question by:mccainz2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 200 total points
ID: 9876382
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
 
LVL 5

Author Comment

by:mccainz2
ID: 9876500
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9876665
In WindowNT or high %comspec% returns cmd.exe
In Win95 or higher %comspec% returns command.exe
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question