forked from bruderstein/PythonScript
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProcessExecute.h
More file actions
64 lines (49 loc) · 1.48 KB
/
ProcessExecute.h
File metadata and controls
64 lines (49 loc) · 1.48 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
#ifndef _PROCESSEXECUTE_H
#define _PROCESSEXECUTE_H
struct PipeReaderArgs;
class ProcessExecute
{
public:
ProcessExecute();
~ProcessExecute();
DWORD 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, DWORD bytesRead, char *buffer);
void writeToFile(PipeReaderArgs *pipeReaderArgs, DWORD bytesRead, char *buffer);
void spoolFile(std::fstream* file, boost::python::object pyStdout, boost::python::object pyStderr);
};
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:
explicit process_start_exception(const char *desc)
: m_desc(desc)
{};
const char *what() const
{ return m_desc.c_str();
}
private:
process_start_exception(); // default constructor disabled
std::string m_desc;
};
#endif