#1 2024-02-06 18:55:22

vs
Member
Registered: 2019-10-21
Posts: 40

RunRedirect and TOnRedirect small confusion of descriptions

Hi!

mormot.core.os

  // - should return true to stop the execution, or false to continue
  .....
  // - the raw process ID (dword on Windows, cint on POSIX) is also supplied
  TOnRedirect = function(const text: RawByteString; pid: cardinal): boolean of object;


  // - will optionally call onoutput() to notify the new output state
  // - can abort if onoutput() callback returns false, or waitfordelayms expires
  ....
  function RunRedirect(const cmd: TFileName; exitcode: PInteger = nil;


Actually, it works fine as described for TOnRedirect. i.e. when the result is false then execution continue.

Offline

#2 2024-02-06 19:10:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: RunRedirect and TOnRedirect small confusion of descriptions

You are right.

Should be better with
https://github.com/synopse/mORMot2/commit/c2b0e3cc

Offline

#3 2024-02-06 19:55:52

vs
Member
Registered: 2019-10-21
Posts: 40

Re: RunRedirect and TOnRedirect small confusion of descriptions

As always, thanks for the lightning-fast response, ab! ))


Add.

Is it possible to add RedirectOutput execution after a certain timeout rather than after the buffer is full?
For long processes with percentage progress, a lot of time passes until the buffer is filled out and the data is transferred to TOnRedirect.
Thanks!

Last edited by vs (2024-02-06 20:06:50)

Offline

#4 2024-02-07 08:25:56

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: RunRedirect and TOnRedirect small confusion of descriptions

On Linux/POSIX, it is running the TOnRedirect every 200 ms at most. OK.

On Windows, it indeed waits for its buffer to be filled.
I started in fact from https://stackoverflow.com/a/25725197/458259 code, which does wait for the full buffer to be filled.
Not what we expect for sure.

I guess it should do the trick:
https://github.com/synopse/mORMot2/commit/e6f42145

Offline

#5 2024-02-07 12:52:35

vs
Member
Registered: 2019-10-21
Posts: 40

Re: RunRedirect and TOnRedirect small confusion of descriptions

Thanks ab.

I tested, but the result is the same.

Offline

#6 2024-02-07 14:23:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: RunRedirect and TOnRedirect small confusion of descriptions

It checks at most every 60ms now.

I tested e.g. with "ping" and it was fine with no delay.

Are you sure it is not the application itself which buffers the output?

Offline

#7 2024-02-07 17:56:10

vs
Member
Registered: 2019-10-21
Posts: 40

Re: RunRedirect and TOnRedirect small confusion of descriptions

Humm, you are rigth. Testing with "ping" works fine.
But with small test program like

 
begin
  for i := 10 to 80 do
    begin
      write(IntToStr(i) + ',');
      sleep(200);
    end;
end. 

I get this log

Start at: 07.02.2024 19:54:58
OnRedirect at: 07.02.2024 19:55:06
10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52
OnRedirect at: 07.02.2024 19:55:12
,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,
Exit Code: 0
function TFoo.OnRedirect(const text: RawByteString; pid: cardinal): boolean;
begin
  Result := False;
//  Writeln(pid);
  if text <> '' then
    begin
      Writeln('OnRedirect at: ' + DateTimeToStr(Now));
      Writeln(text);
    end;
end;

Last edited by vs (2024-02-07 18:00:10)

Offline

Board footer

Powered by FluxBB