Reputation: 1818
According to man popen
, "output popen() streams are fully bufered by default". But for the following code, i can still get all the information of my ls -l
command, without the fflush(p)
command. Does that make sence? I thought I would need the fflush(p)
to flush the command's output that are stored in the user buffer, to the std out.
#include <stdio.h>
int main()
{
FILE *p=popen("ls -l","r");
char buf[100];
memset(buf,0x00,100);
//fflush(p);
fread(buf,sizeof(char),90,p);
printf("%s",buf);
pclose(p);
return 0;
}
Upvotes: 0
Views: 109
Reputation: 213338
That's an input popen()
stream, not an output stream.
The fflush()
function only operates on output or update streams, not input streams.
Upvotes: 3