Skip to main content
GameDev.net gamedev.net
🔒 Locked

Capturing stdout

Started by jmakitalo Jan 7, 2012 at 12:53 PM 7 replies 1.2k views
Original Post
jmakitalo
jmakitalo
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.
SiCrane
SiCrane
In which language? On what platform?
jmakitalo
jmakitalo
Oh sorry, I was a bit hasty. With C++ and I'm hoping that it would be possible platform independently.
SiCrane
SiCrane
That's basically a no. Specific platforms may or may not give you some options.
the_edd
the_edd
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).
jmakitalo
jmakitalo

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.
SiCrane
SiCrane
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.
jmakitalo
jmakitalo
I'll have a look at the streambuffers. Thanks for the advice, although I had hoped this would be more straight-forward .

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.