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?
Share
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.