- 
    
Bug
 - 
    Resolution: Done
 - 
    
P3: Somewhat important
 - 
    Qt Creator 3.1.2, Qt Creator 3.6.0
 - 
    Windows
 
- 
        eba6912e17320cfb8e9b2f963932ad8d968191b3
 
When running C or C++ console application on Windows error occurs: "Cannot obtain a handle to the inferior: The parameter is incorrect".
Problem seems to occur because user application may finish execution before ConsoleProcess::readStubOutput() function is able to process information (PID and thread id) provided via pipe by qtcreator_process_stub.exe and call OpenProcess() on time. Thus OpenProcess() is being called on non-existing process with closed handle, which leads to error.
I was not able to dig into code enough, but I think qtcreator_process_stub.exe should wait for ConsoleProcess and keep handles open (do not call CloseHandle(pi.hProcess) and CloseHandle(pi.hThread) until it is signaled by ConsoleProcess.