Hello, everyone! I hope you can help me with this one...
What I want to do is create a console application that would process user input and then spawn other console applications in the same console window. So I write something like this:
Code:
PROCESS_INFORMATION processInfo;
STARTUPINFO startupInfo;
char userInput[100];
ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
if(CreateProcess(NULL, "ls.exe",
NULL,NULL,FALSE,0,NULL,
NULL,&startupInfo,&processInfo))
{
WaitForSingleObject(processInfo.hProcess,INFINITE);
CloseHandle(processInfo.hThread);
CloseHandle(processInfo.hProcess);
}
printf("What do you do?\n" ); // Works OK
gets(userInput); // Freezes here!
printf("Got it!\n" );
The problem is, after the spawned process ends, the console stops receiving keyboard input (the output still works). I used to think that the child process closes the input handles when it finishes, but I realised that bInheritHandles parameter to CreateProcess() is set to FALSE, so that's not what causes the freeze. What can I do about it?