Skip to content

Instantly share code, notes, and snippets.

@trentbrooks
Created June 19, 2014 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trentbrooks/bfb6412fbbf5e28dfba6 to your computer and use it in GitHub Desktop.
Save trentbrooks/bfb6412fbbf5e28dfba6 to your computer and use it in GitHub Desktop.
ofSystem bug with fclose in openframeworks
string ofSystem(string command){
FILE * ret = NULL;
#ifdef TARGET_WIN32
ret = _popen(command.c_str(),"r");
#else
ret = popen(command.c_str(),"r");
#endif
string strret;
char c;
if (ret == NULL){
ofLogError("ofUtils") << "ofSystem(): error opening return file for command \"" << command << "\"";
}else{
// this method includes the EOF character?
/*do {
c = fgetc (ret);
strret += c;
} while (c != EOF);*/
while((c = fgetc(ret)) != EOF) {
strret += c;
}
//fclose (ret); // WRONG - BUG!
#ifdef TARGET_WIN32
_pclose (ret);
#else
pclose (ret);
#endif
}
return strret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment