[solved] macOS Process and Pipes lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- Espectr0 · 2023-04-15 10:47 Hola, I want to run an app and receive the output texts, in windows it works correctly but in macOS I do not receive anything when executing the app. What can be? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TUWProcessCB = procedure(const TimeElapsed: Double; var Cancel: Boolean); procedure ExecuteAppEx(const AAppFileName: String; const AParams: TStringArray; var Output: TStringList; const ACB: TUWProcessCB = NIL);const  READ_BYTES = 2048; var  AProcess: TProcess;  ACancel: Boolean;  ATimeElapsed: Double;  i: Integer;  MemStream: TMemoryStream;  NumBytes: LongInt;  BytesRead: LongInt;begin  AProcess := TProcess.Create(NIL);  try    AProcess.ShowWindow := swoHide;    AProcess.Executable := AAppFileName;    AProcess.Options    := AProcess.Options + [poUsePipes, poStderrToOutPut];     for i := 0 to High(AParams) do    AProcess.Parameters.Add(AParams[i]);     AProcess.Execute;     ACancel      := False;    ATimeElapsed := 0;    BytesRead := 0;    MemStream := TMemoryStream.Create;    try      while AProcess.Running do      begin        MemStream.SetSize(BytesRead + READ_BYTES);       NumBytes := AProcess.Output.Read((MemStream.Memory + BytesRead)^, READ_BYTES);        if NumBytes > 0 then          Inc(BytesRead, NumBytes)        else          Break;          Application.ProcessMessages;        Sleep(100);        ATimeElapsed += 0.1;        if Assigned(ACB) then        begin          ACB(ATimeElapsed, ACancel);          Application.ProcessMessages;        if ACancel then AProcess.Terminate(-1);        end;      end;    MemStream.SetSize(BytesRead);      if not Assigned(Output) then  Output := TStringList.Create;      Output.LoadFromStream(MemStream);    finally      MemStream.Free;    end;  finally    AProcess.Free;  end;end;  Thanks! ---------------------------------------------------------------------- marcov · 2023-04-15 11:05 How do you check that you don't receive anything? Does it hang or finish? OS behaviour can vary depending on the size of buffers and blocking behaviour of pipes.  A good guard against that is the way that runcommandloop does it by always first checking how many bytes are available and then read those. ---------------------------------------------------------------------- Espectr0 · 2023-04-15 11:23 well the stringlist is empty. I tried running the app, let's say "ffmpeg" in the terminal and there are texts but nothing when running in lazarus process. Can you tell me that it is better to remove my Loop and use RunCommandLoop and possibly work? ---------------------------------------------------------------------- Jonas Maebe · 2023-04-15 11:42 I think ffmpeg writes its output to stderr instead of stdout ---------------------------------------------------------------------- Espectr0 · 2023-04-15 12:02 I'm not sure, but I use the "poStderrToOutPut" flag anyway. ---------------------------------------------------------------------- JdeHaan · 2023-04-15 13:00 This works for me under MacOs: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ProjectRunExecute(Sender: TObject);const  BUF_SIZE = 2048;var  aProcess: TProcess;  aMessages, aErrors: TStringList;  OutputStream : TStream;  BytesRead    : longint;  Buffer       : array[1..BUF_SIZE] of byte;begin  try    aProcess := TProcess.Create(nil);    aMessages := TStringList.Create;    aErrors := TStringList.Create;    aProcess.Executable := your app;    aProcess.Parameters.Add(parameter);     aProcess.Options := [poUsePipes, poStderrToOutPut];    try      aProcess.Execute;      OutputStream := TMemoryStream.Create;      repeat        BytesRead := AProcess.Output.Read(Buffer, BUF_SIZE);        OutputStream.Write(Buffer, BytesRead)      until BytesRead = 0;       with aMessages do      begin        OutputStream.Position := 0; // Required to make sure all data is copied from the start        LoadFromStream(OutputStream);      end;       // Clean up      OutputStream.Free;     except      aErrors.LoadFromStream(aProcess.Stderr);      //MemoOutput.Text := aErrors.Text; // copy errors to a memo      ShowMessage('ExitStatus : ' + IntToStr(aProcess.ExitStatus));    end;  finally    aMessages.Free;    aProcess.Free;    aErrors.Free;  end; end;