| 227 | } |
| 228 | |
| 229 | std::wstring MSWindowsProcess::readOutput(HANDLE handle) |
| 230 | { |
| 231 | const auto kOutputBufferSize = 4096; |
| 232 | wchar_t buffer[kOutputBufferSize]; // NOSONAR -- Idiomatic Win32 |
| 233 | |
| 234 | DWORD bytesRead; |
| 235 | DWORD totalBytesAvail; |
| 236 | DWORD bytesLeftThisMessage; |
| 237 | |
| 238 | // Check if there is data available in the pipe, which prevents `ReadFile` from freezing execution. |
| 239 | if (!PeekNamedPipe(handle, nullptr, 0, nullptr, &totalBytesAvail, &bytesLeftThisMessage)) { |
| 240 | LOG_ERR("could not peek into pipe"); |
| 241 | throw std::runtime_error(windowsErrorToString(GetLastError())); |
| 242 | } |
| 243 | |
| 244 | if (totalBytesAvail == 0) { |
| 245 | return {}; |
| 246 | } |
| 247 | |
| 248 | if (!ReadFile(handle, buffer, kOutputBufferSize, &bytesRead, nullptr)) { |
| 249 | LOG_ERR("could not read from pipe"); |
| 250 | throw std::runtime_error(windowsErrorToString(GetLastError())); |
| 251 | } |
| 252 | |
| 253 | return std::wstring(buffer, bytesRead); |
| 254 | } |
| 255 | |
| 256 | } // namespace deskflow::platform |
nothing calls this directly
no test coverage detected