diff --git a/src/System/ProcessWindows.cpp b/src/System/ProcessWindows.cpp index 19f4393..f15f7dd 100644 --- a/src/System/ProcessWindows.cpp +++ b/src/System/ProcessWindows.cpp @@ -627,7 +627,16 @@ namespace &got, &stream.ov) != 0) { - stream.read_ready = got; + // A zero-byte success is EOF; storing it as "ready" data would + // leave the caller with nothing to wait on (busy loop). + if (got == 0) + { + stream.eof = true; + } + else + { + stream.read_ready = got; + } return; } const DWORD error = ::GetLastError(); @@ -688,8 +697,12 @@ namespace got = stream.read_ready; stream.read_ready = 0; } + if (got == 0) + { + return IoStatus::eof; + } bytes = got; - return got > 0 ? IoStatus::data : IoStatus::none; + return IoStatus::data; } void issue_write(WinStream& stream, diff --git a/tests/standalone/System/Process.cpp b/tests/standalone/System/Process.cpp index e115953..9142d2f 100644 --- a/tests/standalone/System/Process.cpp +++ b/tests/standalone/System/Process.cpp @@ -94,8 +94,12 @@ Void::Testing::Test run_missing_executable_returns_code_127() Void::Testing::Test run_stdout_and_stderr_independent() { +#ifdef _WIN32 + auto r = Void::Process::shell("echo to_stdout & echo to_stderr 1>&2"); +#else auto r = Void::Process::shell( "echo to_stdout; echo to_stderr >&2"); +#endif Void::Testing::expect(r.has_value()); Void::Testing::expect(r->out.find("to_stdout") != std::string::npos); Void::Testing::expect(r->err.find("to_stderr") != std::string::npos);