等到控制台上显示特定消息

时间:2013-08-02 11:01:26

标签: vbscript

这是我的VBS代码

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. 是否可以“而不是10秒的硬编码睡眠”来添加这样的东西,例如: if consolemessage="This will install the product on your computer. Press OK, Cancel" then WshShell.SendKeys "~"
  2. 在上述情况下,可以使用WScript.StdOut来捕获控制台消息吗?我无法做到。

1 个答案:

答案 0 :(得分:1)

使用StdOut方法执行程序时,可以阅读进程的Exec

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