Fix subprocess for Windows

This commit is contained in:
Sebastian Messmer 2018-05-20 22:22:14 -07:00
parent 2ea77d4c26
commit aa4e3c7c08

View File

@ -18,6 +18,7 @@ constexpr const char* openmode = "re";
#define popen _popen #define popen _popen
#define pclose _pclose #define pclose _pclose
#define WEXITSTATUS(a) a #define WEXITSTATUS(a) a
#define WIFEXITED(a) true
constexpr const char* openmode = "r"; constexpr const char* openmode = "r";
#endif #endif
@ -51,8 +52,8 @@ namespace cpputils {
if(returncode == -1) { if(returncode == -1) {
throw std::runtime_error("Error calling pclose. Errno: " + std::to_string(errno)); throw std::runtime_error("Error calling pclose. Errno: " + std::to_string(errno));
} }
if (WIFEXITED(returncode) == 0) { if (!WIFEXITED(returncode)) {
// WEXITSTATUS is only valud if WIFEXITED is 0. // WEXITSTATUS is only valid if WIFEXITED is 0.
throw std::runtime_error("WIFEXITED returned " + std::to_string(WIFEXITED(returncode))); throw std::runtime_error("WIFEXITED returned " + std::to_string(WIFEXITED(returncode)));
} }
return WEXITSTATUS(returncode); return WEXITSTATUS(returncode);