Jump to content
  • Advertisement
Sign in to follow this  
jmakitalo

Capturing stdout

This topic is 2530 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a way to capture data sent to stdout, or for a general stream for that matter? By this I mean that when a message is sent to stdout, the program would be notified by this and it could then post the message to e.g. a graphical console window.

Share this post


Link to post
Share on other sites
Advertisement
Presumably you mean the stdout of another process that your program is launching?

If so, the most portable way is to use something like this (which isn't an official boost library yet), or this (whose Windows implementation is still a bit sketchy, to say the least).

Share this post


Link to post
Share on other sites

Presumably you mean the stdout of another process that your program is launching?


No. My game uses stdout to report load and game time messages. I would like that during the game, these messages could also be seen in a graphical console. So for that I would need to be able to capture the messages somehow and then draw them.

So lets say that in the game a player joins the server and I have something like


cout << "Player joined the game.\n";


I would like that this message could be drawn by a function, say, drawMessageToGraphicalConsole(string msg) which I have implemented, without changing every "cout" in the code.

Share this post


Link to post
Share on other sites
If you only want to redirect std::cout, and not other uses of stdout, then you can use a custom streambuf object. edd²'s website has an example of how you can do that here.

Share this post


Link to post
Share on other sites
I'll have a look at the streambuffers. Thanks for the advice, although I had hoped this would be more straight-forward :).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!