MCPcopy Create free account
hub / github.com/deskflow/deskflow / readOutput

Method readOutput

src/lib/platform/MSWindowsProcess.cpp:229–254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

227}
228
229std::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

Callers

nothing calls this directly

Calls 1

windowsErrorToStringFunction · 0.85

Tested by

no test coverage detected