From the man page:
Note that output popen() streams are fully buffered by default.
This means that for a standard implementation, between 512 and 8192 bytes must be written before the data is automatically cleared to the base file descriptor.
Call fflush()or, better yet, callsetvbuf(fp, nullptr, _IONBF, 0);
source
share