I'm running a process (and it does run - I see its output in its entirety - console app outputs text), with CreateProcessW. When I wait on the process information object's handle, I get back that it's an invalid handle. What am I doing wrong here?
Makes me think I can't wait on it because the process is already gone before the Wait? I don't see why that would affect the signaling of the process info object though... So I think that can't be it.
DWORD dwCode = 0;
ZeroMemory ( &si, sizeof ( STARTUPINFOW));
si.cb = sizeof ( STARTUPINFOW);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = bShow ? SW_SHOWNORMAL : SW_HIDE;
CStringW strCommand = L"c:\\test\\runme.exe";
bRes = CreateProcessW(NULL, strCommand.GetBuffer(), NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
DWORD dwWaitResult = WaitForSingleObject(&pi.hProcess, 3000);
// if the process finished, we break out
if(dwWaitResult == WAIT_OBJECT_0)
else if(dwWaitResult == WAIT_FAILED)
// ALWAYS GETTING HERE - GetLastError() returns 6- (INVALID HANDLE). How come?