KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Waiting for executable to finish
Topic Summary: I want to use Adv Scripting to launch executable and wait for the executable to finish before continuing with the script
Created On: 06/11/2009 10:31 PM
Status: Post and Reply
Linear : Threading : Single : Branch
 Waiting for executable to finish   - jsarver - 06/11/2009 10:31 PM  
 Waiting for executable to finish   - Matt Chambers - 06/12/2009 08:03 AM  
 Waiting for executable to finish   - jsarver - 07/01/2009 10:53 PM  
 Waiting for executable to finish   - Matt Chambers - 07/02/2009 08:28 AM  
Keyword
 06/11/2009 10:31 PM
User is offline View Users Profile Print this message


jsarver
Junior Member

Posts: 3
Joined: 06/11/2009

I am using Dragon Medical 10.0.  I have many very small executable files created with another scripting program that I would like to be able to run sequentially from within one dragon script.  What is the most efficient way to launch the executable and then have the script wait until it successfully completes before proceeding with the rest of the script?  I appreciate any help or suggestions of resources that I may wish to explore.

-------------------------
Dragon Medical 10.0, XP pro sp2, Motion J3400 tablet, dual-core 1.4, 3mb L2 cache, BW900 Bluetooth with Anycom USB bluetooth dongle.
 06/12/2009 08:03 AM
User is offline View Users Profile Print this message


Matt Chambers
Top-Tier Member

Posts: 379
Joined: 10/02/2006

One way to do this would be to have the scripts written with the other program display some sort of window when they are done.  Then you could use the WaitforWindow technique.  If you'll search this forum, you will see examples of using the WaitforWindow coding.

Of course, you could always just use a timed wait period, but that doesn't seem very interesting or efficient. 

-------------------------
 07/01/2009 10:53 PM
User is offline View Users Profile Print this message


jsarver
Junior Member

Posts: 3
Joined: 06/11/2009

I found another solution on a blog that involves writing a function that waits for the executable to finish:

 

http://www.mjtnet.com/blog/2009/06/04/calling-macro-scheduler-scripts-from-vbvba/

 

  1.     Private Declare Sub Sleep Lib "kernel32" ( _  
  2.         ByVal dwMilliseconds As Long)  
  3.     Private Declare Function GetExitCodeProcess Lib "kernel32" ( _  
  4.         ByVal hProcess As LongByVal lpExitCode As LongAs Long  
  5.     Private Declare Function timeGetTime Lib "winmm.dll" () As Long  
  6.     Private Declare Function OpenProcess Lib "kernel32" ( _  
  7.         ByVal dwDesiredAccess As LongByVal bInheritHandle As LongByVal dwProcessId As LongAs Long  
  8.     Private Const STILL_ACTIVE = &H103  
  9.     Private Const PROCESS_QUERY_INFORMATION = &H400  
  10.     Private Declare Function CloseHandle Lib "kernel32" ( _  
  11.         ByVal hObject As LongAs Long  
  12.   
  13.     Public Function ShellAndWait( _  
  14.      ByVal sShell As String, _  
  15.             Optional ByVal eWindowStyle As Integer = vbNormalFocus, _  
  16.             Optional ByRef sError As String = "", _  
  17.             Optional ByVal lTimeOut As Long = 2000000000 _  
  18.          As Boolean  
  19.         Dim hProcess As Long  
  20.         Dim lR As Long  
  21.         Dim lTimeStart As Long  
  22.         Dim bSuccess As Boolean  
  23.   
  24.         On Error GoTo ShellAndWaitError  
  25.   
  26.         ' This is v2 which is somewhat more reliable:  
  27.         hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(sShell, eWindowStyle))  
  28.         If (hProcess = 0) Then  
  29.             sError = "This program could not determine whether the process started." & _  
  30.                  "Please watch the program and check it completes."  
  31.             ' Only fail if there is an error - this can happen  
  32.             ' when the program completes too quickly.  
  33.         Else  
  34.             bSuccess = True  
  35.             lTimeStart = timeGetTime()  
  36.             Do  
  37.                 ' Get the status of the process  
  38.                 GetExitCodeProcess(hProcess, lR)  
  39.                 ' Sleep during wait to ensure the other process gets  
  40.                 ' processor slice:  
  41. DoEvents:       Sleep(100)  
  42.                 If (timeGetTime() - lTimeStart > lTimeOut) Then  
  43.                     ' Too long!  
  44.                     sError = "The process has timed out."  
  45.                     lR = 0  
  46.                     bSuccess = False  
  47.                 End If  
  48.             Loop While lR = STILL_ACTIVE  
  49.         End If  
  50.         ShellAndWait = bSuccess  
  51.   
  52.         Exit Function  
  53.   
  54. ShellAndWaitError:  
  55.         sError = Err.Description  
  56.         Exit Function  
  57.     End Function 

 



-------------------------
Dragon Medical 10.0, XP pro sp2, Motion J3400 tablet, dual-core 1.4, 3mb L2 cache, BW900 Bluetooth with Anycom USB bluetooth dongle.
 07/02/2009 08:28 AM
User is offline View Users Profile Print this message


Matt Chambers
Top-Tier Member

Posts: 379
Joined: 10/02/2006

Cool! thanks for sharing!


-------------------------
Statistics
27356 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 1 users logged in.
The most users ever online was 2028 on 04/05/2013 at 07:36 PM.
There are currently 116 guests browsing this forum, which makes a total of 117 users using this forum.

FuseTalk Standard Edition v4.0 - © 1999-2013 FuseTalk™ Inc. All rights reserved.