Problem
It was easy for me to figure out a method for setting console colors in C++ using windows.h and std::cout. One such method is shown here:
HANDLE stdout = GetStdHandle(STD_OUTPUT_HANDLE); //get handle of console
CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
GetConsoleScreenBufferInfo(stdout, &bufferInfo); //save current color scheme
SetConsoleTextAttribute(stdout, 0x4); //change console color
std::cout << "This is red text" << std::endl;
SetConsoleTextAttribute(stdout, bufferInfo.wAttributes); //restore old colors
Sure enough, when I run my program from a console window, the colors change as expected. The problem is, when this is run from an msbuild script, I use exec:
<Exec Command="myExecutable.exe" />
When run from the msbuild script, the colors are not affected by the program. The text still outputs in the call to std::cout, but it's just the normal console window colors.
Hypothesis
My guess is that the call to exec writes to stdout via different handle than STD_OUTPUT_HANDLE. Either that, or the msbuild exec sets its own console attributes. I've tried getting the parent console, but haven't had any luck.
Any ideas?