Kriti
Kriti

Reputation: 191

Waiting till the particular message is displayed on console

Here is my VBS code

Set wshshell = wscript.CreateObject("WScript.Shell")
Wshshell.run "C:\Temp\Executable.exe -c -dir C:\Productdir"
'Wait till "This will install the product on your computer. Press OK, Cancel" appears
WScript.Sleep 10000
WshShell.SendKeys "~"   
  1. Is it possible "rather than hard-coded sleep of 10 secs" to add something like this for e.g. if consolemessage="This will install the product on your computer. Press OK, Cancel" then WshShell.SendKeys "~"?
  2. Can WScript.StdOut be used to capture the console messages in the above case? I was not able to do it.

Upvotes: 1

Views: 1018

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200313

You can read StdOut of a process when you execute the program using the Exec method.

Set wshshell = wscript.CreateObject("WScript.Shell")
Set p = Wshshell.Exec("C:\Temp\Executable.exe -c -dir C:\Productdir")

Do While p.Status = 0
  output = ""
  Do Until p.StdOut.AtEndOfStream
    c = p.StdOut.Read(1)
    WScript.StdOut.Write c  'write read characters to the command prompt
    output = output & c
    If InStr(output, "This will install the product") > 0 Then
      'do stuff
      Exit Do
    End If
  Loop
  WScript.Sleep 100
Loop

Upvotes: 1

Related Questions