Skip to content

Commit

Permalink
fixed RunCommand/RunRedirect OnOuput() call on Windows
Browse files Browse the repository at this point in the history
- it should not wait for the whole buffer to be filled, but redirect the data ASAP
- as RunRedirect() does on POSIX
  • Loading branch information
Arnaud Bouchez committed Feb 7, 2024
1 parent ae8cda1 commit e6f4214
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/core/mormot.core.os.posix.inc
Expand Up @@ -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));
Expand Down
14 changes: 8 additions & 6 deletions src/core/mormot.core.os.windows.inc
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/mormot.commit.inc
@@ -1 +1 @@
'2.2.7016'
'2.2.7017'

0 comments on commit e6f4214

Please sign in to comment.