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?

4

2 回答 2

0

这就是你所追求的?http://msdn.microsoft.com/en-us/library/ms682079%28v=VS.85%29.aspx

您的要求有点含糊,尽管我想这就是为什么您还没有得到想要的东西的原因。

于 2010-09-15T18:08:17.600 回答
0

我不确定是否真的可以在不注入子进程并挂钩控制台 api 和 WriteFile 的情况下创建完整的控制台替换。

另一方面,应该可以替换 cmd.exe,只要确保您实际创建了一个控制台程序并且您应该获得一个控制台,并且 CreateProcess 应该确保子进程获得相同的控制台而不会弄乱 i/o 句柄。

于 2010-09-15T19:02:34.337 回答