News | Articles | Libraries | Developer Tools | Books | Forum Links | Search   
Sections:
 

QA: How can I start another program and wait until it will be finished?

By Vassili Philippov, August 08, 2001.
Print version

Question

I need to start another executable file and wait until it will be finished. How can I do it?

Answer

Use CreateProcess function to start another program and WaitForSingleObject function to wait until the program will be finished.

You could also use RunExecutable and RunExecutableAndWait function of STUtil library that hides details.

Note: Pocket PC doesn't support local file names. All file names should contain full path like _T("\\sindows\\CreateAssetFile.exe").

Source code

Here is a sample code that starts CreateAssetFile.exe program and waits until it will be finished:

// Start CreateAssetFile.exe PROCESS_INFORMATION pi; if (!::CreateProcess(TEXT("\\windows\\CreateAssetFile.exe"), NULL, NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi)) { return FALSE; } // Wait until CreateAssetFile.exe will be finished ::WaitForSingleObject(pi.hProcess, INFINITE); return TRUE;

The same functionality implemented using STUtil library:

return CSTUtil::RunExecutableAndWait(TEXT("\\windows\\CreateAssetFile.exe"));

Discuss

Discuss this article. Here you can write your comments and read comments of other developers.
Rate this article:     Poor Excellent    
 12345 
© 2001-2005 Pocket PC Developer Network, a division of Spb Software House