Created
June 19, 2014 00:11
-
-
Save trentbrooks/bfb6412fbbf5e28dfba6 to your computer and use it in GitHub Desktop.
ofSystem bug with fclose in openframeworks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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