ReadFile can return 0 bytes written while the pipe is still valid
MODIFY
src/vcpkg/base/system.process.cpp
src/vcpkg/base/system.process.cpp
@@ -589,11 +589,13 @@ namespace vcpkg
unsigned long bytes_read = 0;
static constexpr int buffer_size = 1024 * 32;
auto buf = std::make_unique<char[]>(buffer_size);
- while (ReadFile(child_stdout, (void*)buf.get(), buffer_size, &bytes_read, nullptr) && bytes_read > 0)
+ while (ReadFile(child_stdout, (void*)buf.get(), buffer_size, &bytes_read, nullptr))
{
f(StringView{buf.get(), static_cast<size_t>(bytes_read)});
}
+ Debug::print("ReadFile() finished with GetLastError(): ", GetLastError(), '\n');
+
CloseHandle(child_stdout);
return proc_info.wait();
@@ -811,6 +813,7 @@ namespace vcpkg
return 1;
}
char buf[1024];
+ // Use fgets because fread will block until the entire buffer is filled.
while (fgets(buf, 1024, pipe))
{
data_cb(StringView{buf, strlen(buf)});

ReadFile can return 0 bytes written while the pipe is still valid (#299)