I am trying to parse a stream by using popen with a command that returns a constant stream of output lines.
This makes the application to get stuck on the fgets()
call.
Here's the method:
std::string MyClass::InvokeCmd(std::string command)
{
std::string result;
std::array<char, 128> buffer;
FILE *pipe = popen(command.c_str(), "r");
while (fgets(buffer.data(), 128, pipe) != NULL)
{
result += buffer.data();
}
}
pclose(pipe);
return result;
}
The command is a ROS command:
rostopic hz /topicname
The command runs continuously and produces one line of output approximately every second.
If I wait for around 30 sec (looks like flush time of a buffer) I do see the data.