Redirecting printf()? stdout accutually?
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?
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.
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.
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
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.
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.
With Windows at least, you can get and set the standard input, output and error handles with the GetStdHandle() and SetStdHandle().
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement