0

我正在尝试在我的 QTP 脚本中使用 DoEvents - 但出现错误 -类型不匹配:'DoEvents'

下面是我的脚本:

Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400
Const SYNCHRONIZE = &H100000
Extern.Declare micHwnd, "CloseHandle", "kernel32", "CloseHandle", micLong
Extern.Declare micHwnd, "WaitForSingleObject", "kernel32", "WaitForSingleObject", micLong, micLong
Extern.Declare micHwnd, "OpenProcess", "kernel32", "OpenProcess", micLong, micLong, micLong
Extern.Declare micHwnd, "GetExitCodeProcess", "kernel32", "GetExitCodeProcess", micLong, micLong


Public Function Run_XML(exeStr, ByVal logFile)

Dim pid, ExitEvent
Dim lineStr
Dim okFlg
Dim hProcess
Dim wait_time

wait_time =  input_details.Items()(19)

xmlCount = "0"
okFlg = 0

Dim SystemProcess
Set SystemProcess = DotNetFactory.CreateInstance("System.Diagnostics.Process")

Dim processStartInfo
Set processStartInfo = DotNetFactory.CreateInstance("System.Diagnostics.ProcessStartInfo")
processStartInfo.UseShellExecute = false

processStartInfo.FileName = "plink.exe"
processStartInfo.Arguments = Chr(34) + " -load " +  Chr(34) + session_name + Chr(34) + " -l " + Chr(34) + login_id + Chr(34) + " -pw " + Chr(34) + pwd + Chr(34) + " -m " + Chr(34) + cmd_dir + "commands.txt" + Chr(34) + " >> " + Chr(34) + log_dir & log_filename + Chr(34)
Dim myProcess
Set myProcess = SystemProcess.Start(processStartInfo)
pid = myProcess.Id

hProcess = Extern.OpenProcess(SYNCHRONIZE, False, pid)
ExitEvent = Extern.WaitForSingleObject(hProcess, (wait_time + 5) * 1000)

Do 
    Extern.GetExitCodeProcess hProcess, ExitEvent
    DoEvents
Loop While ExitEvent = STILL_ACTIVE

Extern.CloseHandle(hProcess)

End Function

您能否建议 Doevents 在 QTP 中是否有效?如果没有,那么任何其他替代方案或任何其他使用相同方法的方法?

4

2 回答 2

1

如果您只想等待进程退出再继续,您可以调用 Process.WaitForExit()。

myProcess.WaitForExit

但是,您在另一个答案的评论中声明要等待控制台进程的特定输出。如果您控制台应用程序/批处理文件或任何正在逐行输出内容的内容,您可以像这样阅读它:

'Your other ProcessStartInfo code here. Configure 2 extra options as below.
processStartInfo.UseShellExecute = false
processStartInfo.RedirectStandardOutput = true

Dim myProcess
Set myProcess = SystemProcess.Start(processStartInfo)

Dim stdOut
'Redirect standard output so you can read it.
Set stdOut = myProcess.StandardOutput
Do
  Wait 0, 100
  'Store the line in a variable and check it for whatever condition you want instead of printing as below.
  print myProcess.StandardOutput.ReadLine()
Loop While (not myProcess.HasExited)
'Get any leftover output at the end of execution.
print myProcess.StandardOutput.ReadToEnd()
于 2014-01-31T18:35:34.163 回答
0

DoEventsQTP 不支持。

QTP 使用 VBScript 作为其脚本语言,而 VBScript 不支持DoEvents.

于 2014-01-29T17:52:45.877 回答