Question

I am trying to use DoEvents in my QTP script - but getting error - Type mismatch: 'DoEvents'

Below is my script:

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

Can you please suggest if Doevents is valid in QTP or not? If not then any other alternative or any other method to use the same?

Was it helpful?

Solution

If you just want to wait for the process to exit before proceeding, you can call Process.WaitForExit().

myProcess.WaitForExit

However, you state in comments on another answer that you want to wait for specific output from the console process. If you console app/batch file or whatever is outputting things line-by-line you could read it like this:

'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()

OTHER TIPS

DoEvents is not supported by QTP.

QTP uses VBScript as its scripting language and VBScript doesn't supports DoEvents.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top