Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9213853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:50:43+00:00 2026-06-18T01:50:43+00:00

Problem It was easy for me to figure out a method for setting console

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:50:44+00:00Added an answer on June 18, 2026 at 1:50 am

    The most likely thing is that MSBuild connects your executable to a pipe. When you write something to a pipe MSBuild reads it from the other end, then it may do some processing: like writing to screen, to logs, etc… The issue is that you cannot transfer colors through a pipe. In fact you can check that your stdout handle is not a console buffer using GetFileType, which will return FILE_TYPE_CHAR for a console but FILE_TYPE_PIPE if my hypothesis is correct. You also should check whether your console function calls succeeded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

An easy problem, but for some reason I just can't figure this out today.
I have a problem that I can't figure out myself. I've tried using LEFT
This seems to be an easy problem but i can't figure out. I need
Seems like an easy problem, but I am not able to figure it out
This seems like an extremely easy problem but alas I cannot figure it out
I am trying to solve a fairly easy problem but can't quite figure out
My problem maybe easy to solve, but I really can't figure it out. I
Determining the Fibonacci sequence is easy enough to figure out: int num = 0;
I Have a quite simple question that I just cant figure out. The method
I cannot figure this one out ... that means it's got to be an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.