20

I am creating a process with that code:

CreateProcess(NULL, "process.exe", NULL, NULL, TRUE, 0, NULL, NULL, %ini_processo, %processo_info);

I need my code to wait for my process to finish before resuming. What is the method with C++ ?

01BTC10
  • 506
  • 3
  • 9
  • 19
  • 10
    Maybe I have leaks with my search skill. – 01BTC10 Feb 26 '12 at 14:48
  • 12
    WaitForSingleObject(processo_info.hProcess, INFINITE). Don't forget to CloseHandle() the returned handles. And it looks like you ought to be using the Process class if % actually compiles. Use & otherwise. – Hans Passant Feb 26 '12 at 14:51
  • Thank you. I begun to learn C++ a week ago and been searching for this solution since yesterday. – 01BTC10 Feb 26 '12 at 14:58
  • See also http://stackoverflow.com/questions/1846385/running-a-windows-program-and-detect-when-it-ends-with-c – rogerdpack Jun 24 '15 at 07:37

1 Answers1

36

You just call WaitForSingleObject on the handle CreateProcess returns.

Rotem
  • 21,452
  • 6
  • 62
  • 109
Nikola Smiljanić
  • 26,745
  • 6
  • 48
  • 60