-
popen and fgets problem
I use popen to get the output of a process, and fgets to read a line. But if the process is still running, will I get buffer overflow (line)in the fgets?
char [2048] line;
FILE *fd;
fd = popen("non-stop-program","r");
while(fgets(line, 2048, fd)) {
.. do things
}
-
> will I get buffer overflow (line)in the fgets?
No - fgets will never overflow the buffer you give it (unless you deliberately tell it the wrong size).
It should behave as if you had redirected the output to a file, then fopen'ed that file for reading.