Skip to content

Commit 13c7c5a

Browse files
author
전상현
committed
[100_System] ShellExecuteByPipe에서 수집하는 콘솔 문자가 프로그램에 따라 달라서 std::string 형태로 얻어오도록 변경함
1 parent f3bd27d commit 13c7c5a

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

Src/100_System/KernelObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ namespace core
120120
void ExitProcess(int nExitCode);
121121

122122
int ShellExecuteByPipe(std::string strCmdLine, std::string& strOutput);
123-
int ShellExecuteByPipe(std::wstring strCmdLine, std::wstring& strOutput);
123+
int ShellExecuteByPipe(std::wstring strCmdLine, std::string& strOutput);
124124

125125
HANDLE CreateThread(int (*pfEntry)(void* pContext), void* pContext, E_THREAD_PRIORITY nPriority = THREAD_PRIORITY_MIDDLE);
126126
ECODE SuspendThread(HANDLE hThread);

Src/100_System/KernelObjectT_Linux_Mac.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ namespace core
186186
}
187187

188188
//////////////////////////////////////////////////////////////////////////
189-
int ShellExecuteByPipe(std::tstring strCmdLine, std::tstring& strOutput)
189+
int ShellExecuteByPipe(std::tstring strCmdLine, std::string& strOutput)
190190
{
191191
FILE* pPipe = NULL;
192192
signal(SIGPIPE, SIG_IGN); // sigpipe 무시.
@@ -201,7 +201,7 @@ namespace core
201201
const size_t tBuffSize = 64;
202202
char szBuf[tBuffSize];
203203
while (NULL != ::fgets(szBuf, tBuffSize, pPipe))
204-
strOutput += TCSFromMBS(szBuf);
204+
strOutput += szBuf;
205205

206206
nExitCode = ::pclose(pPipe);
207207
pPipe = NULL;

Src/100_System/KernelObjectT_Win.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ namespace core
228228

229229
//////////////////////////////////////////////////////////////////////////
230230
// Deprecated, CANNOT hide console window
231-
static int ShellExecuteByPipe_Old(std::tstring strCmdLine, std::tstring& strOutput)
231+
static int ShellExecuteByPipe_Old(std::tstring strCmdLine, std::string& strOutput)
232232
{
233233
FILE* pPipe = NULL;
234234
try
@@ -240,7 +240,7 @@ namespace core
240240
const size_t tBuffSize = 64;
241241
char szBuf[tBuffSize];
242242
while(::fgets(szBuf, tBuffSize, pPipe))
243-
strOutput += TCSFromMBS(szBuf);
243+
strOutput += szBuf;
244244
}
245245
catch (std::exception& e)
246246
{
@@ -273,7 +273,7 @@ namespace core
273273
}
274274

275275
//////////////////////////////////////////////////////////////////////////
276-
static ECODE ShellExecuteByPipe_New(std::tstring strCmdLine, std::tstring& strOutput, DWORD& dwExitCode)
276+
static ECODE ShellExecuteByPipeWorker(std::tstring strCmdLine, std::string& strOutput, DWORD& dwExitCode)
277277
{
278278
PROCESS_INFORMATION stProcessInfo = { 0, };
279279
HANDLE hStdOutPair[2] = { 0, };
@@ -305,11 +305,9 @@ namespace core
305305
if (!::CreateProcess(NULL, (LPTSTR)strCmdLine.c_str(), NULL, NULL, TRUE, 0, NULL, NULL, &stStartupInfo, &stProcessInfo))
306306
throw exception_format(TEXT("Failed to CreateProcess(%s)"), strCmdLine.c_str());
307307

308-
std::string strTempOutput;
309308
while (WAIT_TIMEOUT == ::WaitForSingleObject(stProcessInfo.hProcess, 100))
310-
ReadContextFromPipe(hStdOutPair[0], strTempOutput);
311-
ReadContextFromPipe(hStdOutPair[0], strTempOutput);
312-
strOutput = TCSFromUTF8(strTempOutput);
309+
ReadContextFromPipe(hStdOutPair[0], strOutput);
310+
ReadContextFromPipe(hStdOutPair[0], strOutput);
313311

314312
if (!GetExitCodeProcess(stProcessInfo.hProcess, &dwExitCode))
315313
Log_Warn(TEXT("GetExitCodeProcess failure."));
@@ -337,10 +335,10 @@ namespace core
337335
}
338336

339337
//////////////////////////////////////////////////////////////////////////
340-
int ShellExecuteByPipe(std::tstring strCmdLine, std::tstring& strOutput)
338+
int ShellExecuteByPipe(std::tstring strCmdLine, std::string& strOutput)
341339
{
342340
DWORD dwExitCode = 0;
343-
ECODE nRet = ShellExecuteByPipe_New(strCmdLine, strOutput, dwExitCode);
341+
ECODE nRet = ShellExecuteByPipeWorker(strCmdLine, strOutput, dwExitCode);
344342
if (EC_SUCCESS != nRet)
345343
return ShellExecuteByPipe_Old(strCmdLine, strOutput);
346344

0 commit comments

Comments
 (0)