Skip to content
Advertisement

Can’t redirect printf to pipe

I want to redirect the output of printf to a pipe, but for some reason it doesn’t seem to work. What does work is using write instead.

This is my program

JavaScript

if I replace write with the commented line, my program just blocks

Advertisement

Answer

Either add a new line character (n) to your output or use fflush() as Barmar suggests:

fprintf(stderr, “Error while forking #1!n”);

or

fprintf(stderr, “Error while forking #1!”); fflush(stderr);

btw, it’s received, not recieved 😉

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement