I'm testing this example for programming with pipes and it seems pretty straightforward.
But I was wondering what happen if the first argument of first popen() call (the string containing a shell command) holds a 'while do' loop.
For example, if I execute this shell command for 3 seconds, I get this output:
tomas@ubuntu64:~$ while true; do ps -A; sleep 1; done | grep init
1 ? 00:00:03 init
1 ? 00:00:03 init
1 ? 00:00:03 init
so the grep is working in each iteration.
However, if I do it through the C language example, changing the popen() of the example by:
FILE* ps_pipe = popen("while true; do ps -A; sleep 1; done", "r");
I get no output result when executing the compiled C program.
Anyone can shed some light on this?