forked from bruderstein/PythonScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessExecute.h
More file actions
68 lines (54 loc) · 1.56 KB
/
ProcessExecute.h
File metadata and controls
68 lines (54 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef _PROCESSEXECUTE_H
#define _PROCESSEXECUTE_H
#include <fstream>
#include "stdafx.h"
struct PipeReaderArgs;
class ProcessExecute
{
public:
ProcessExecute();
~ProcessExecute();
long execute(const TCHAR *commandLine, boost::python::object pyStdout, boost::python::object pyStderr, boost::python::object pyStdin, bool spoolToFile = false);
protected:
static bool isWindowsNT();
static const int STREAM_NAME_LENGTH = 3;
static const char *STREAM_NAME_STDOUT;
static const char *STREAM_NAME_STDERR;
private:
static DWORD WINAPI pipeReader(void *args);
void writeToPython(PipeReaderArgs *pipeReaderArgs, int bytesRead, char *buffer);
void writeToFile(PipeReaderArgs *pipeReaderArgs, int bytesRead, char *buffer);
void spoolFile(std::fstream* file, boost::python::object pyStdout, boost::python::object pyStderr);
HANDLE m_hStdOutReadPipe;
HANDLE m_hStdOutWritePipe;
HANDLE m_hStdErrReadPipe;
HANDLE m_hStdErrWritePipe;
};
struct PipeReaderArgs
{
ProcessExecute* processExecute;
HANDLE hPipeRead;
HANDLE hPipeWrite;
HANDLE stopEvent;
HANDLE completedEvent;
boost::python::object pythonFile;
/// Set if the output should be spooled to the fileHandle member
/// if false, then write directly to pythonFile
bool toFile;
std::fstream *file;
HANDLE fileMutex;
const char *streamName;
};
class process_start_exception
{
public:
process_start_exception(const char *what)
: m_what(what)
{};
const char *what() const
{ return m_what.c_str();
}
private:
std::string m_what;
};
#endif