CreateProcess and console handles

This is a discussion on CreateProcess and console handles within the Windows Programming forums, part of the Platform Specific Boards category; Hello, everyone! I hope you can help me with this one... What I want to do is create a console ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    25

    CreateProcess and console handles

    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?

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    You can try other ways to get keyboard input, getline, cin<< etc.
    And are you sure it works before the process?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. One process with two console windows
    By siavoshkc in forum Windows Programming
    Replies: 8
    Last Post: 01-30-2009, 03:13 PM
  2. Console problem
    By maxorator in forum Windows Programming
    Replies: 2
    Last Post: 12-22-2005, 09:41 AM
  3. Write in many command prompts
    By cfriend in forum Windows Programming
    Replies: 1
    Last Post: 09-15-2004, 01:32 AM
  4. Redirecting console output to sockets
    By junbin in forum Windows Programming
    Replies: 1
    Last Post: 01-19-2003, 02:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21