#include "Process.hpp"
#ifdef _WIN32
-# error "TODO: windows implementation of Process"
+# include <tchar.h>
+# include <windows.h>
#else
-# include <cstdio>
# include <fcntl.h>
+# include <signal.h>
# include <unistd.h>
# include <sys/wait.h>
#endif
+#include <cstdio>
#include <stdexcept>
using namespace std;
size_t ReadOut(void *buffer, size_t max_len);
size_t ReadErr(void *buffer, size_t max_len);
+ void Terminate();
int Join();
#ifdef _WIN32
return impl->ReadErr(buffer, max_len);
}
+void Process::Terminate() {
+ if (!joined) {
+ impl->Terminate();
+ }
+}
+
int Process::Join() {
if (joined) {
return status;
#endif
}
+void Process::Impl::Terminate() {
+#ifdef _WIN32
+ if (!TerminateProcess(pi.hProcess, -1)) {
+#else
+ if (kill(pid, SIGTERM) == -1) {
+#endif
+ throw runtime_error("failed to terminate child process");
+ }
+}
+
int Process::Impl::Join() {
#ifdef _WIN32
CloseHandle(fd_in[1]);