MCPcopy Create free account
hub / github.com/Xtra-Computing/thundersvm / getBashOutput

Method getBashOutput

src/thundersvm/util/log.cpp:987–1012  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

985#endif // ELPP_OS_ANDROID
986
987 const std::string OS::getBashOutput(const char* command) {
988#if (ELPP_OS_UNIX && !ELPP_OS_ANDROID && !ELPP_CYGWIN)
989 if (command == nullptr) {
990 return std::string();
991 }
992 FILE* proc = nullptr;
993 if ((proc = popen(command, "r")) == nullptr) {
994 ELPP_INTERNAL_ERROR("\nUnable to run command [" << command << "]", true);
995 return std::string();
996 }
997 char hBuff[4096];
998 if (fgets(hBuff, sizeof(hBuff), proc) != nullptr) {
999 pclose(proc);
1000 if (hBuff[strlen(hBuff) - 1] == '\n') {
1001 hBuff[strlen(hBuff) - 1] = '\0';
1002 }
1003 return std::string(hBuff);
1004 } else {
1005 pclose(proc);
1006 }
1007 return std::string();
1008#else
1009 ELPP_UNUSED(command);
1010 return std::string();
1011#endif // (ELPP_OS_UNIX && !ELPP_OS_ANDROID && !ELPP_CYGWIN)
1012 }
1013
1014 std::string OS::getEnvironmentVariable(const char* variableName, const char* defaultVal,
1015 const char* alternativeBashCommand) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected