From 134a31acc9c515fae6a4c4d873cf851c380508d8 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Mon, 30 Mar 2015 13:39:56 -0400 Subject: [PATCH 1/3] Make sure output is read even if it won't be logged. --- src/libs/wcautil/qtexec.cpp | 125 ++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 62 deletions(-) diff --git a/src/libs/wcautil/qtexec.cpp b/src/libs/wcautil/qtexec.cpp index 5c70cf3ba..d66ed7652 100644 --- a/src/libs/wcautil/qtexec.cpp +++ b/src/libs/wcautil/qtexec.cpp @@ -109,6 +109,7 @@ static HRESULT CreatePipes( } static HRESULT LogOutput( + __in BOOL fLogOutput, __in HANDLE hRead ) { @@ -136,76 +137,79 @@ static HRESULT LogOutput( ExitOnLastError(hr, "Failed to read from handle."); } - // Check for UNICODE or ANSI output - if (bFirst) + if (fLogOutput) { - if ((isgraph(pBuffer[0]) && isgraph(pBuffer[1])) || - (isgraph(pBuffer[0]) && isspace(pBuffer[1])) || - (isspace(pBuffer[0]) && isgraph(pBuffer[1])) || - (isspace(pBuffer[0]) && isspace(pBuffer[1]))) + // Check for UNICODE or ANSI output + if (bFirst) { - bUnicode = FALSE; + if ((isgraph(pBuffer[0]) && isgraph(pBuffer[1])) || + (isgraph(pBuffer[0]) && isspace(pBuffer[1])) || + (isspace(pBuffer[0]) && isgraph(pBuffer[1])) || + (isspace(pBuffer[0]) && isspace(pBuffer[1]))) + { + bUnicode = FALSE; + } + + bFirst = FALSE; } - bFirst = FALSE; - } - - // Keep track of output - if (bUnicode) - { - hr = StrAllocConcat(&szLog, (LPCWSTR)pBuffer, 0); - ExitOnFailure(hr, "failed to concatenate output strings"); - } - else - { - hr = StrAllocStringAnsi(&szTemp, (LPCSTR)pBuffer, 0, CP_OEMCP); - ExitOnFailure(hr, "failed to allocate output string"); - hr = StrAllocConcat(&szLog, szTemp, 0); - ExitOnFailure(hr, "failed to concatenate output strings"); - } - - // Log each line of the output - pNext = szLog; - pEnd = wcschr(szLog, L'\r'); - if (NULL == pEnd) - { - pEnd = wcschr(szLog, L'\n'); - } - while (pEnd && *pEnd) - { - // Find beginning of next line - pEnd[0] = 0; - ++pEnd; - if ((pEnd[0] == L'\r') || (pEnd[0] == L'\n')) + // Keep track of output + if (bUnicode) { - ++pEnd; + hr = StrAllocConcat(&szLog, (LPCWSTR)pBuffer, 0); + ExitOnFailure(hr, "failed to concatenate output strings"); + } + else + { + hr = StrAllocStringAnsi(&szTemp, (LPCSTR)pBuffer, 0, CP_OEMCP); + ExitOnFailure(hr, "failed to allocate output string"); + hr = StrAllocConcat(&szLog, szTemp, 0); + ExitOnFailure(hr, "failed to concatenate output strings"); } - // Log output - hr = StrAllocString(&sczEscaped, pNext, 0); - ExitOnFailure(hr, "Failed to allocate copy of string"); - - hr = StrReplaceStringAll(&sczEscaped, L"%", L"%%"); - ExitOnFailure(hr, "Failed to escape percent signs in string"); - - hr = StrAnsiAllocString(&szWrite, sczEscaped, 0, CP_OEMCP); - ExitOnFailure(hr, "failed to convert output to ANSI"); - WcaLog(LOGMSG_STANDARD, szWrite); - - // Next line - pNext = pEnd; - pEnd = wcschr(pNext, L'\r'); + // Log each line of the output + pNext = szLog; + pEnd = wcschr(szLog, L'\r'); if (NULL == pEnd) { - pEnd = wcschr(pNext, L'\n'); + pEnd = wcschr(szLog, L'\n'); + } + while (pEnd && *pEnd) + { + // Find beginning of next line + pEnd[0] = 0; + ++pEnd; + if ((pEnd[0] == L'\r') || (pEnd[0] == L'\n')) + { + ++pEnd; + } + + // Log output + hr = StrAllocString(&sczEscaped, pNext, 0); + ExitOnFailure(hr, "Failed to allocate copy of string"); + + hr = StrReplaceStringAll(&sczEscaped, L"%", L"%%"); + ExitOnFailure(hr, "Failed to escape percent signs in string"); + + hr = StrAnsiAllocString(&szWrite, sczEscaped, 0, CP_OEMCP); + ExitOnFailure(hr, "failed to convert output to ANSI"); + WcaLog(LOGMSG_STANDARD, szWrite); + + // Next line + pNext = pEnd; + pEnd = wcschr(pNext, L'\r'); + if (NULL == pEnd) + { + pEnd = wcschr(pNext, L'\n'); + } } - } - hr = StrAllocString(&szTemp, pNext, 0); - ExitOnFailure(hr, "failed to allocate string"); + hr = StrAllocString(&szTemp, pNext, 0); + ExitOnFailure(hr, "failed to allocate string"); - hr = StrAllocString(&szLog, szTemp, 0); - ExitOnFailure(hr, "failed to allocate string"); + hr = StrAllocString(&szLog, szTemp, 0); + ExitOnFailure(hr, "failed to allocate string"); + } } // Print any text that didn't end with a new line @@ -288,10 +292,7 @@ HRESULT WIXAPI QuietExec( ReleaseFile(hInRead); // Log output if we were asked to do so - if (fLogOutput) - { - LogOutput(hOutRead); - } + LogOutput(fLogOutput, hOutRead); // Wait for everything to finish ::WaitForSingleObject(oProcInfo.hProcess, dwTimeout); From a65ebde3bca8736423f88a5f168343ca0dd4c93d Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Mon, 30 Mar 2015 14:19:10 -0400 Subject: [PATCH 2/3] Rename LogOutput as it no longer always logs output per Mike's feedback. --- src/libs/wcautil/qtexec.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/wcautil/qtexec.cpp b/src/libs/wcautil/qtexec.cpp index d66ed7652..e7c08b718 100644 --- a/src/libs/wcautil/qtexec.cpp +++ b/src/libs/wcautil/qtexec.cpp @@ -108,7 +108,7 @@ static HRESULT CreatePipes( return hr; } -static HRESULT LogOutput( +static HRESULT HandleOutput( __in BOOL fLogOutput, __in HANDLE hRead ) @@ -292,7 +292,7 @@ HRESULT WIXAPI QuietExec( ReleaseFile(hInRead); // Log output if we were asked to do so - LogOutput(fLogOutput, hOutRead); + HandleOutput(fLogOutput, hOutRead); // Wait for everything to finish ::WaitForSingleObject(oProcInfo.hProcess, dwTimeout); From ed4faea75fdf7b4e5bf0a57dda7944b0002bee0b Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Mon, 30 Mar 2015 14:20:25 -0400 Subject: [PATCH 3/3] Add comment. --- src/libs/wcautil/qtexec.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/wcautil/qtexec.cpp b/src/libs/wcautil/qtexec.cpp index e7c08b718..d82c8d04b 100644 --- a/src/libs/wcautil/qtexec.cpp +++ b/src/libs/wcautil/qtexec.cpp @@ -291,7 +291,7 @@ HRESULT WIXAPI QuietExec( ReleaseFile(hErrWrite); ReleaseFile(hInRead); - // Log output if we were asked to do so + // Log output if we were asked to do so; otherwise just read the output handle HandleOutput(fLogOutput, hOutRead); // Wait for everything to finish