I would like to know if it is possible that an utility yields binary data (i.e. graphical images) and outputs them through IO console, while another application, instructed about the nature of those data and informed of the number of the incoming bytes, is able to read it from IO console.
Share
Yes, it is possible. While it’s true that often
stdin/stdoutare meant to be text there are many programs that are designed to get binary input or write binary output from standard I/O channels.The only thing you should pay attention is that normally
stdout/stdinare opened in text mode under Windows, so you should switch them to binary mode to avoid character translation.To set binary mode on
stdin/stdouton Windows you need to use the _setmode call:Note also to pay attention to file buffering. Often programs will flush the buffer on newlines ONLY when the output is to an interactive console and not when it’s another process. So if you need synchronizaton remember to call
fflushafter writing a message because otherwise the other process will not be able to get the data.