It’s probably a long-shot that anyone can answer this without seeing all the source code and libraries, etc., but I’ll try.
I have a program X written in C++ using boost-1.41. If X outputs with std::cout, then running X from another program using fp=popen("X", "r") allows X‘s output to be seen via fgets(buff, 1024, fp).
Now if I change X to use printf() instead of std::cout, the output of X is no longer seen. However, running X from bash produces the output as expected.
What could possibly explain this difference?! I suspect boost is involved here, but I don’t know much about boost.
Note: I am happy sticking to std::cout and my problem is solved. But I’m trying to understand what the problem was with printf().
The reason is that you probably used
std::endlwithstd::cout. That, in addition to writing a newline character, also flushes the output buffer.To do the same with
printfyou can just addfflush(stdout);after the call.