You cannot reliably get all console output from a process by only redirecting its standard handles. As soon as it uses raw console I/O functions, these will only work with a real console and not file handles.
Normally, the default, unredirected STD_INPUT_HANDLE
, STD_OUTPUT_HANDLE
and STD_ERROR_HANDLE
are only pseudo-handles, as in the sense of not being handles known to the NT kernel for that process. The ReadFile
and WriteFile
APIs have a hack in them that checks for these pseudo-handles and redirects the call to ReadConsoleA
and WriteConsoleA
as appropriate. However, all the console APIs only operate on console pseudo-handles (named console input buffers and console screen buffers) and will fail when passed a real file handle.
Now, because of this redirection, and the fact that most programs use the file APIs when writing to or reading from the console means that it is possible to have some level of redirection, but since what you want to do is a complete console emulator, this will not be enough. You will not be able to capture any of the calls that, for example, change the size or attributes of the screen buffer, reads from it, creates alternate ones, etc.
If you are not scared of assembly language and reverse-engineering, you can look into hooking the various console APIs into the target process (and their children), or, in the case of Windows 7, reimplementing conhost.exe
.