Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there any way GetExitCodeProcess could set the exit code to the wrong value?
    primarykey
    data
    text
    <p>I'm maintaining code written by someone <em>just</em> before they retired, which means I can't find them to ask questions. :-) This is basically a C++ wrapper to launch a program. The chunk of code in question is this:</p> <pre><code>BOOL bSuccess = CreateProcess(NULL, (char *)strBatFile.c_str(), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, strLocalWorkingDir.c_str(), &amp;si, &amp;pi ); if( bSuccess ) { DWORD dwMillisec = INFINITE; DWORD dwWaitStatus = WaitForSingleObject( pi.hProcess, dwMillisec ); if( dwWaitStatus == WAIT_OBJECT_0 ) { DWORD dwExitCode = NULL; GetExitCodeProcess( pi.hProcess, &amp;dwExitCode ); nRet = (int)dwExitCode; } CloseHandle( pi.hThread ); CloseHandle( pi.hProcess ); } else nRet = START_PROCESS_FAILED; </code></pre> <p>If just one instance is run at a time, it always works fine. If multiple are run within a very short time frame, though, about half of them are having dwExitCode set to 1 instead of 0, even though the process isn't crashing, and the log file that internal program writes is completing.</p> <p>So to clarify, the process is always starting fine, and it's always getting into the if statements, but it's the value of dwExitCode set by GetExitCodeProcess that isn't containing what's expected. Since we error check on this, we're flagging a bunch of these runs as incomplete when they in fact are fine.</p> <p>Is there any way this value could be set to something different than the process exit code? And/or is there a utility I could run at the same time to confirm the exit codes are what I think they are?</p> <p>Thanks! </p> <p><strong>ETA:</strong> Just realised this is putting the internal program call in a .bat file - "C:\\ --flags etc..." and then calling that as a command line in the second argument, rather than just calling it directly using lpApplicationName. No idea if this makes a difference! But when I print the PID of the process, I can see it's the PID for a cmd.exe process, and then our program has a child PID. However, when I trace in Process Monitor, I can see that both parent and child are exiting with exit code 0.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload