|
@@ -2,6 +2,7 @@
|
|
|
#include "ScriptExecutor.h"
|
|
|
#include <fstream>
|
|
|
#include <io.h>
|
|
|
+#include <fcntl.h>
|
|
|
|
|
|
CScriptExecutor::CScriptExecutor(void)
|
|
|
{
|
|
@@ -160,6 +161,11 @@ int CScriptExecutor::RedirectStdout(LPSTARTUPINFO si /*=NULL*/)
|
|
|
if((stream = freopen(m_szLogPath, "w", stdout)) == NULL)
|
|
|
return -1;
|
|
|
#else
|
|
|
+ SECURITY_ATTRIBUTES sa;
|
|
|
+ sa.bInheritHandle = TRUE;
|
|
|
+ sa.lpSecurityDescriptor = NULL;
|
|
|
+ sa.nLength = sizeof(sa);
|
|
|
+
|
|
|
// 创建stdout的管道;
|
|
|
if (!CreatePipe(&m_hStdOutRead, &m_hStdOutWrite, NULL, 0))
|
|
|
{
|
|
@@ -167,17 +173,10 @@ int CScriptExecutor::RedirectStdout(LPSTARTUPINFO si /*=NULL*/)
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- int wpfd = _open_osfhandle((intptr_t)m_hStdOutWrite, 0);
|
|
|
- if (_dup2(wpfd, _fileno(stdout)) != 0)
|
|
|
- {
|
|
|
- printf("Error:dup2调用失败");
|
|
|
- }
|
|
|
- _close(wpfd);
|
|
|
-
|
|
|
- if (!SetStdHandle(STD_OUTPUT_HANDLE, m_hStdOutWrite))
|
|
|
- {
|
|
|
- printf("Error:重定向失败\n");
|
|
|
- }
|
|
|
+ int wpfd = _open_osfhandle((intptr_t)m_hStdOutWrite, _O_TEXT);
|
|
|
+ FILE* pOutFile = _fdopen(wpfd, "w");
|
|
|
+ *stdout = *pOutFile;
|
|
|
+ setvbuf(stdout, NULL, _IONBF, 0);
|
|
|
#endif
|
|
|
}
|
|
|
|