From e6f4214552a2f57c0b80376ae29fab6cbf850413 Mon Sep 17 00:00:00 2001 From: Arnaud Bouchez Date: Wed, 7 Feb 2024 09:24:08 +0100 Subject: [PATCH] fixed RunCommand/RunRedirect OnOuput() call on Windows - it should not wait for the whole buffer to be filled, but redirect the data ASAP - as RunRedirect() does on POSIX --- src/core/mormot.core.os.posix.inc | 2 +- src/core/mormot.core.os.windows.inc | 14 ++++++++------ src/mormot.commit.inc | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/core/mormot.core.os.posix.inc b/src/core/mormot.core.os.posix.inc index 014b456cf..ef7614264 100644 --- a/src/core/mormot.core.os.posix.inc +++ b/src/core/mormot.core.os.posix.inc @@ -3448,7 +3448,7 @@ var var u: RawUtf8; begin - result := false; + result := false; // return false on pipe closed if WaitReadPending(fd, wait) then begin n := fpread(fd, tmp, SizeOf(tmp)); diff --git a/src/core/mormot.core.os.windows.inc b/src/core/mormot.core.os.windows.inc index 81f40e878..0e2fb9f15 100644 --- a/src/core/mormot.core.os.windows.inc +++ b/src/core/mormot.core.os.windows.inc @@ -4847,22 +4847,24 @@ var procedure RedirectOutput(flush: boolean); var new: RawByteString; - pending: Int64; - n: cardinal; + pending, n: cardinal; tmp: TSynTempBuffer; begin repeat - Win32Check(GetFileSizeEx(rd, pending)); - if pending = 0 then + pending := 0; + if not PeekNamedPipe(rd, nil, 0, nil, @pending, nil) or + (pending = 0) then begin if (not flush) and Assigned(onoutput) and onoutput('', processinfo.dwProcessId) then - exitcode := WAIT_OBJECT_0; // returned true to abort + exitcode := WAIT_OBJECT_0; // onoutput() returned true to abort break; end; + if pending > SizeOf(tmp) then + pending := SizeOf(tmp); n := 0; - Win32Check(ReadFile(rd, tmp, SizeOf(tmp), n, nil)); + Win32Check(ReadFile(rd, tmp, pending, n, nil)); if n <= 0 then break; if redirected <> nil then diff --git a/src/mormot.commit.inc b/src/mormot.commit.inc index fc73d5fcc..cb04278a6 100644 --- a/src/mormot.commit.inc +++ b/src/mormot.commit.inc @@ -1 +1 @@ -'2.2.7016' +'2.2.7017'