Search code examples
windowswinapiconsoleconsole-redirect

Can the console output of a Windows console application be captured fully (incl. advanced manipulations)?


It is a trivial matter of redirecting a console program's standard input/output, but what about if the program uses advanced console functions? Like outputting colored text, throwing the cursor around and manipulating the console buffer directly? Can that also be captured and redirected to my own program for processing?

Note: I'm talking about the scenario where my app (not necessarily a console app) runs a console app and redirects its input/output to itself.

Note 2: In the end I'll want C# code, but for now let's stick to bare Win32 API and C or C++. I don't think it will be possible without PInvoke anyway, so let's get the basic principle down first (if at all possible).


Solution

  • Unlike Linux, all color IO is not going to be captured with simple redirecting, so the only way to capture it is to hook on WinAPI calls (i.e. you will need to intercept system calls), which require administrative privileges, fragile and suspicious.