C: printf() hangs linux pipes
I've written a simple I/O echoing program in C to test a problem with a bigger real program. Here, linux FD redirection doesn't work.
The echoing program (aka a.out) is: Code:
#include <stdio.h> From Bash, I run it as: Code:
$ mkfifo IN OUT Let's compare this a.out with cat, which instead works as expected: Code:
$ mkfifo IN OUT What's wrong with a.out? |
Quote:
Change your source code to the following (note the text in bold font), and it should function as expected: Code:
#include <stdio.h> |
|
Yes, fflush() solves the problem. So it seems stdin/out work differently if they run across an interactive console or a pipe. In fact, executing a.out directly with no redirections thru pipes produces immediate outputs to console and doesn't require fflush().
|
Quote:
|
All times are GMT -5. The time now is 06:15 AM. |