- 1 year ago
CreateProcess: cmd.exe does not exit when child process is finished
If you are encountering an issue where the cmd.exe
process does not exit after a child process has finished, there are several potential causes and solutions:
Ensure that the child process is actually finishing: Before attempting to troubleshoot the
cmd.exe
process, verify that the child process is actually finishing and that it is not hanging or stuck in a loop.Use the appropriate
CreateProcess
flags: When callingCreateProcess
, ensure that you are using the appropriate flags to wait for the child process to finish and to allow it to inherit handles. Specifically, you should use theCREATE_NO_WINDOW
flag to prevent thecmd.exe
window from appearing, and theCREATE_DEFAULT_ERROR_MODE
andCREATE_NEW_CONSOLE
flags to configure the process to inherit handles and to run in a new console.Use
WaitForSingleObject
to wait for the child process to finish: After callingCreateProcess
, useWaitForSingleObject
to wait for the child process to finish. This will ensure that your application does not exit until the child process has completed and that thecmd.exe
process is terminated.Use
STARTUPINFO
to configure the process: You can use theSTARTUPINFO
structure to configure the child process, including the console window and the handles that it inherits. This can help to ensure that the child process runs correctly and that thecmd.exe
process exits when the child process finishes.
If none of these solutions resolve the issue, you may need to seek additional support from a technical expert or from the Windows community.