views:

50

answers:

2

Why would I want to? Because I'm writing my own cmd.exe replacement! I can CreateProcess and pass in handles to pipes for stdin and stdout and stderr, and I see how I can AllocConsole, FreeConsole, and AttachConsole, but how do I tell child programs that my program is the console?

More detail for clarification: I've got a window that can display text and accept input. I display the text "C:>" for instance. The user types "foo.exe". I locate foo.exe on the path, and call CreateProcess on it. If it writes to stdout, I display that text on the screen. If it reads from stdin, I pass in whatever keystrokes the user has pressed. When the process terminates, I print the prompt again. So far, so good. It all works. But then I try foo2.exe, which does a CreateFile on CONOUT$, which fails because there is no console attached to the process. What does cmd.exe do to make it's children see it as a console?

A: 

This what you're after? http://msdn.microsoft.com/en-us/library/ms682079%28v=VS.85%29.aspx

Your request is kinda vague, although I guess that's why you haven't already got what you're looking for.

Rushyo
I'll try and edit it to be clearer.
Mike Elkins
+1  A: 

I'm not sure if it actually possible to create a full console replacement without injecting into the child process and hooking the console api's and WriteFile.

A cmd.exe replacement on the other hand should be possible, just make sure you actually created a console program and you should get a console and CreateProcess should make sure the child process gets the same console without messing with the i/o handles.

w0lo