I am wrapping a command line process in a WinForms app and redirecting the output so it can be piped into either an RTF control or a listbox. It would be nice to be able to preserve the foreground color of the text as it comes through so it can be displayed properly in the form. Is there a way to do this?
+2
A:
Most probably not. Colored console output is done using the SetConsoleTextAttribute API call, which operates on console screen buffers.
If you redirect output from a console application, you have no console screen buffer to work with. SetConsoleTextAttribute returns zero (indicating failure) if you redirect output, which means that the application could not even set colors.
Sofahamster
2010-01-01 22:57:35
Is there an alternative to redirecting output then? What about a hidden console window and scraping the output?
Charles
2010-01-01 23:33:36
You might find a solution in the source code of Console2 (http://sourceforge.net/projects/console/) a "Windows console window enhancement" that manages to implement console windows with colors, tabs, ...
Sofahamster
2010-01-02 00:01:04
I will check that out. Thanks.
Charles
2010-01-02 00:16:39