Make your own free website on Tripod.com

Run an App and wait till it is finished

Back Up Next

Author: Eric Aling (03 okt 2000)
Accessed:
Download:  Download runandwait.zip (7KB) (runandwait.zip, PB6.5, 7Kb)

This file will show how to run an external application and wait until that app is finished.

Basically it is starting a new process using the CreateProcess() API. This function returns immediately, even if the application is not ended yet. But afterwards, we can call the WaitForSingleObject() API function, in which we can specify the new process handle. This function returns when the process ends so there you have the solution.

Oh, (thanx to Chris Smith) and if on some applications seem to hang, change the function with the following:

******* w_main - of_RunAndWait (Original)

WaitForSingleObject(lstr_PI.hProcess, INFINITE)

******* w_main - of_RunAndWait (Original)

// WaitForSingleObject returns 0 when the Object is signaled

do while WaitForSingleObject(lstr_PI.hProcess, 500) <> 0

    yield()

loop

******* End

 

Enjoy!

 

Back Up Next