Fix subprocess for osx

This commit is contained in:
Sebastian Messmer 2018-05-20 13:51:12 -07:00
parent ca68102a50
commit dfd6a0414f
1 changed files with 11 additions and 2 deletions

View File

@ -3,14 +3,23 @@
#include <stdexcept>
#include <cerrno>
#if !defined(_MSC_VER)
#if defined(__APPLE__)
#include <sys/wait.h>
constexpr const char* openmode = "r";
#elif !defined(_MSC_VER)
#include <sys/wait.h>
constexpr const char* openmode = "re";
#else
#define popen _popen
#define pclose _pclose
#define WEXITSTATUS(a) a
constexpr const char* openmode = "r";
#endif
using std::string;
@ -23,7 +32,7 @@ namespace cpputils {
FILE *subprocess = popen(command.c_str(), openmode);
if (!subprocess)
{
throw std::runtime_error("Error starting subprocess "+command);
throw std::runtime_error("Error starting subprocess "+command + ". Errno: " + std::to_string(errno));
}
return subprocess;
}