I have a bash script which I'm reading the results from in my program. Ptr
is a simple popen()
wrapper.
bool getResult(const char* path){
Ptr f(path);
char buf[1024];
while (fgets(buf, sizeof(buf), f) == 0) {
if(errno == EINTR)
continue;
log.error("Error (%d) : %s",errno,path);
return false;
}
...
return true;
}
This works fine, but Ptr f(path)
is not exception safe, so I replace it with:
Ptr f; // empty constructor, does nothing
char buf[1024];
try{
Ptr f(path);
}catch(Exception& e){
vlog.error("Could not open file at %s",path);
return false;
}
When run (and the file exists) I get the following error:
/etc/my_script: line 165: echo: write error: Broken pipe
That line of the script is just:
echo $result
What is going on?