Saturday, May 24, 2008

How do I wait for a process to terminate?

Suppose you want to execute a command line utility and wait for it to finish before continuing. Then you can construct the command line including the executable path at the beginning and call the following function.
int ExecAndWait(char *cmdline, char *workingdir)
{
STARTUPINFO startupinfo = {0};
PROCESS_INFORMATION procinfo = {0};

startupinfo.cb = sizeof(startupinfo);
if(CreateProcess(NULL, cmdline, NULL, NULL, FALSE,
CREATE_NO_WINDOW, NULL, workingdir,
&startupinfo, &procinfo) == 0)
return 0;

WaitForSingleObject(procinfo.hProcess, INFINITE);
return 1;
}

1 comment:

dsu4i7c7ks said...

Made potential through Pixar’s USD file format, this takes away the ache of importing and exporting scenes in various packages and allows him to iterate quicker. Customize all NVIDIA-built extensions and apps at a source code-level go well with|swimsuit} your|to fit your} wants. This website requires Javascript so as to to} view all its content material. Please enable Javascript so as to to} entry all of the functionality of this website. Here are the instructions method to|tips on how to} enable JavaScript in your web browser. Do you have have} questions Puffer Jackets about their technical parameters, costs or elective accessories?