@@ -16,10 +16,6 @@ const char *ProcessExecute::STREAM_NAME_STDOUT = "OUT";
1616const char *ProcessExecute::STREAM_NAME_STDERR = " ERR" ;
1717
1818ProcessExecute::ProcessExecute ()
19- : m_hStdOutReadPipe (NULL ),
20- m_hStdOutWritePipe (NULL ),
21- m_hStdErrReadPipe (NULL ),
22- m_hStdErrWritePipe (NULL )
2319{
2420}
2521
@@ -56,6 +52,8 @@ long ProcessExecute::execute(const TCHAR *commandLine, boost::python::object pyS
5652 PipeReaderArgs stderrReaderArgs;
5753 // Only used if spooling, but we need to delete it later.
5854 TCHAR tmpFilename[MAX_PATH] = {0 };
55+ HANDLE hStdOutReadPipe, hStdOutWritePipe;
56+ HANDLE hStdErrReadPipe, hStdErrWritePipe;
5957
6058 Py_BEGIN_ALLOW_THREADS
6159 try
@@ -73,12 +71,12 @@ long ProcessExecute::execute(const TCHAR *commandLine, boost::python::object pyS
7371 sa.nLength = sizeof (SECURITY_ATTRIBUTES);
7472 sa.bInheritHandle = TRUE ;
7573
76- if (!::CreatePipe (&m_hStdOutReadPipe , &m_hStdOutWritePipe , &sa, DEFAULT_PIPE_SIZE))
74+ if (!::CreatePipe (&hStdOutReadPipe , &hStdOutWritePipe , &sa, DEFAULT_PIPE_SIZE))
7775 {
7876 throw process_start_exception (" Error creating pipe for stdout" );
7977 }
8078
81- if (!::CreatePipe (&m_hStdErrReadPipe , &m_hStdErrWritePipe , &sa, DEFAULT_PIPE_SIZE))
79+ if (!::CreatePipe (&hStdErrReadPipe , &hStdErrWritePipe , &sa, DEFAULT_PIPE_SIZE))
8280 {
8381 throw process_start_exception (" Error creating pipe for stderr" );
8482 }
@@ -88,17 +86,17 @@ long ProcessExecute::execute(const TCHAR *commandLine, boost::python::object pyS
8886
8987
9088 stdoutReaderArgs.processExecute = this ;
91- stdoutReaderArgs.hPipeRead = m_hStdOutReadPipe ;
92- stdoutReaderArgs.hPipeWrite = m_hStdOutWritePipe ;
89+ stdoutReaderArgs.hPipeRead = hStdOutReadPipe ;
90+ stdoutReaderArgs.hPipeWrite = hStdOutWritePipe ;
9391 stdoutReaderArgs.pythonFile = pyStdout;
9492 stdoutReaderArgs.stopEvent = stopEvent;
9593 stdoutReaderArgs.completedEvent = CreateEvent (NULL , FALSE , FALSE , NULL );
9694 stdoutReaderArgs.streamName = STREAM_NAME_STDOUT;
9795 stdoutReaderArgs.toFile = false ;
9896
9997 stderrReaderArgs.processExecute = this ;
100- stderrReaderArgs.hPipeRead = m_hStdErrReadPipe ;
101- stderrReaderArgs.hPipeWrite = m_hStdErrWritePipe ;
98+ stderrReaderArgs.hPipeRead = hStdErrReadPipe ;
99+ stderrReaderArgs.hPipeWrite = hStdErrWritePipe ;
102100 stderrReaderArgs.pythonFile = pyStderr;
103101 stderrReaderArgs.stopEvent = stopEvent;
104102 stderrReaderArgs.completedEvent = CreateEvent (NULL , FALSE , FALSE , NULL );
@@ -167,17 +165,17 @@ long ProcessExecute::execute(const TCHAR *commandLine, boost::python::object pyS
167165 STARTUPINFO si;
168166
169167
170- ::SetHandleInformation (m_hStdOutReadPipe , HANDLE_FLAG_INHERIT, 0 );
171- ::SetHandleInformation (m_hStdErrReadPipe , HANDLE_FLAG_INHERIT, 0 );
168+ ::SetHandleInformation (hStdOutReadPipe , HANDLE_FLAG_INHERIT, 0 );
169+ ::SetHandleInformation (hStdErrReadPipe , HANDLE_FLAG_INHERIT, 0 );
172170
173171 // initialize STARTUPINFO struct
174172 ::ZeroMemory ( &si, sizeof (STARTUPINFO) );
175173 si.cb = sizeof (STARTUPINFO);
176174 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
177175 si.wShowWindow = SW_HIDE;
178176 si.hStdInput = NULL ;
179- si.hStdOutput = m_hStdOutWritePipe ;
180- si.hStdError = m_hStdErrWritePipe ;
177+ si.hStdOutput = hStdOutWritePipe ;
178+ si.hStdError = hStdErrWritePipe ;
181179
182180 ::ZeroMemory ( &pi, sizeof (PROCESS_INFORMATION) );
183181
@@ -224,6 +222,10 @@ long ProcessExecute::execute(const TCHAR *commandLine, boost::python::object pyS
224222 CloseHandle (hStdoutThread);
225223 CloseHandle (hStderrThread);
226224 CloseHandle (stopEvent);
225+ CloseHandle (hStdOutReadPipe);
226+ CloseHandle (hStdOutWritePipe);
227+ CloseHandle (hStdErrReadPipe);
228+ CloseHandle (hStdErrWritePipe);
227229
228230 if (processStartSuccess)
229231 {
@@ -317,8 +319,6 @@ DWORD WINAPI ProcessExecute::pipeReader(void *args)
317319 }
318320 }
319321
320- CloseHandle (pipeReaderArgs->hPipeRead );
321- CloseHandle (pipeReaderArgs->hPipeWrite );
322322 SetEvent (pipeReaderArgs->completedEvent );
323323
324324 return 0 ;
0 commit comments