I have this C code snippet which runs on a coreOS machine:
-----------------------------------------------------------------------------
char db[512];
snprintf(db, 512, "%s %s", <some command>, <args of the command>);
FILE* pipe = popen(db, "r");
if (!pipe) {
return NULL;
}
char buf[256];
while (fgets(buf, sizeof(buf), pipe) != NULL) {
<DEBUG POINT 1>
<some code utilising buf>
}
<DEBUG POINT 2>
-----------------------------------------------------------------------------
Now the command that is being executed and which is streaming to the Pipe in
eventually calling a python code which returns None(Null) with the given
argument.
The problem that I'm facing is that fgets is not able to handle the response
and the program crashes when it tries to execute fgets() on the Pipe. What I
mean is that on reaching while(), my program exits and is not able to reach
either DEBUG POINT 1 or 2. I have tried searching for possible solutions but am
not able to find anything.
Another interesting thing is when I run the same code on a Amazon Linux
Machine, it works fine and I get the desired behaviour.
Can someone please guide me in the right direction.