Passing binary streams
If the standard stream being passed across a system() call is opened
in binary mode, any reads or writes issued in the called program occur
at the next byte in the file. On return, the position of the file
is wherever the called program is positioned. This includes any possible
repositions made by the called program if the file is enabled for
positioning. Because output to binary files is done byte by byte,
all bytes are written to stdout and stderr in the order they are
written. This is shown in the following example:
printf("123");
printf("456");
system("CHILD"); ------> int main(void) { putc('7',stdout);}
printf("89");
The output from this example is: 123456789
Memory files are always opened in binary mode, even if you specify text. Any standard streams redirected to memory files and passed across system() calls will be treated as binary files. UNIX file system files are also treated as binary files, because they do not contain any real record boundaries. Memory files are not passed across calls to the POSIX system() function.
If freopen() is applied to a C standard stream, thereby creating a binary stream, then the results of I/O to the associated standard stream across a system() call are undefined.