2014-01-29 80 views
0

我想在我的QTP腳本中使用的DoEvents - 但得到的錯誤 - 類型不匹配:調用DoEvents'如何在QTP 11中使用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與否?如果沒有,那麼使用相同的其他方法或任何其他方法?

回答

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

DoEvents不受QTP支持。

QTP使用VBScript作爲其腳本語言,VBScript不支持DoEvents

+0

是否有任何其他替代'DoEvents'?我正在使用它來等待Unix批處理命令等待特定的輸出,然後打破循環進行進一步處理。有什麼,你可以幫助/建議可以做? – Krishna

+0

那麼你現在的代碼是不是沒有'DoEvents',即'Loop While ExitEvent = STILL_ACTIVE'?還有'STILL_ACTIVE'在您的代碼中的某處定義?如果不是,那麼循環將不會工作,因爲STILL_ACTIVE被當作變量處理,因此值將爲'Null'。它應該是一個字符串? –

+0

另外,您不應該需要DoEvents才能等待控制檯應用程序完成其任務。 –