Jump to content
  • Advertisement
Sign in to follow this  
DvDmanDT

Redirecting printf()? stdout accutually?

This topic is 4840 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

Hello everyone.. I know you can redirect stdout to a file with reopen().. My question is if you can redirect it to say, sockets, an ingame console (like FPS games have) or something else? Is it possible? And if so, how?

Share this post


Link to post
Share on other sites
Advertisement
Nope. You might be able to do something in Linux with low level files (open() close(), etc), because in Linux, sockets and files are handled the same way. I'm not really sure about anything with low level files though.

I'm almost certain you can't redirect to a in-game console or socket in WIndows though. Your best bet would be to write another layer on top of printf(), and use varg lists like printf does.

Share this post


Link to post
Share on other sites
I think I did manage to get stdout redirected once using VB.. Like.. GetStandardOutput or something.. Hmm.. You'd think it should be possible.. :p

Share this post


Link to post
Share on other sites
There is a tool though that does that sort of redirection called netcat. You simply pipe your command into netcat [and provide it some parameters] and netcat sends everything it hears on stdin to whatever parameters you specify.

I'm fairly certain there's a windows port of it.

Though personally, I just use stringstream and send the result to my quake-style console or networking layer as the pre-made string. Others use boost::format, or lexical_cast to format/stringify their data.

Share this post


Link to post
Share on other sites
Hmm.. How about the CreateFile() function, in combination with SetStdHandle(), to redirect it to a temporary buffer, then every now and then check it and send/output it however you may wish? Would that work?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!