Make subprocess work on windows
This commit is contained in:
parent
d7e95606f6
commit
3296ae92f7
@ -1,7 +1,16 @@
|
|||||||
#include "subprocess.h"
|
#include "subprocess.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#if !defined(_MSC_VER)
|
||||||
#include <sys/wait.h>
|
#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;
|
using std::string;
|
||||||
|
|
||||||
@ -33,7 +42,7 @@ namespace cpputils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FILE *Subprocess::_call(const string &command) {
|
FILE *Subprocess::_call(const string &command) {
|
||||||
FILE *subprocess = popen(command.c_str(), "r");
|
FILE *subprocess = popen(command.c_str(), openmode);
|
||||||
if (!subprocess)
|
if (!subprocess)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Error starting subprocess "+command);
|
throw std::runtime_error("Error starting subprocess "+command);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user