Lazarus

Free Pascal => General => Topic started by: Dzandaa on August 04, 2021, 08:33:23 pm

Title: TProcess output to a TMemo
Post by: Dzandaa on August 04, 2021, 08:33:23 pm
Hi,

Is it possible to write the output (String) of a TProcess in a TMemo Line by Line?

Thank you.

Title: Re: TProcess output to a TMemo
Post by: winni on August 04, 2021, 09:26:33 pm
Hi!

I don't understand the reason of this question, but:

You can assign your output string to a temporay stringlist and add the lines one by one:

Code: Pascal  [Select][+][-]
  1. ...
  2. tmpStringList := TStringList.create;
  3. tmpStringList.text := OutputString;
  4. for i := 0 to tmpStringList.count - 1 do
  5.     memo1.lines.add (tmpStringList[i]);
  6. tmpStringList.free;
  7. ...

Winni
Title: Re: TProcess output to a TMemo
Post by: Edson on August 04, 2021, 10:01:06 pm
I would recommend https://github.com/t-edson/UnTerminal

It's a wrapper for a wrapper for TProcess with prompt detection and event driven.
Title: Re: TProcess output to a TMemo
Post by: Jurassic Pork on August 05, 2021, 12:42:00 am
hello,
Is it possible to write the output (String) of a TProcess in a TMemo Line by Line?.
what do you mean for that ? send the stdout and stderr of the process in real  time to the tmemo while process is running ?

with UnTerminal  you can do that -> see attachment  ( Example 2 of UnTerminal)

Edson -> I have modified your example because On Windows Strings must be converted from OEM to UTF8  (for latin characters ex : é )
Code: Pascal  [Select][+][-]
  1. uses LazUTF8;
  2. // ....
  3.  
  4. procedure TForm1.procLineCompleted(const lin: string);
  5. begin
  6.   if LinPartial then begin
  7.     //Estamos en la línea del prompt
  8.     Memo1.Lines[Memo1.Lines.Count-1] := ConsoleToUTF8(lin);  //reemplaza última línea
  9.     LinPartial := false;
  10.   end else begin  //caso común
  11.     Memo1.Lines.Add(ConsoleToUTF8(lin));
  12.   end;
  13. end;
  14.  
  15. procedure TForm1.procReadData(nDat: integer; const lastLin: string);
  16. begin
  17.   LinPartial := true;   //marca bandera
  18.   Memo1.Lines.Add(ConsoleToUTF8(lastLin));   //agrega la línea que contiene al prompt
  19. end;              

Friendly, J.P
Title: Re: TProcess output to a TMemo
Post by: Dzandaa on August 05, 2021, 02:16:38 pm
Thank you very much.

I've try it and it work :)

in linux C++ using cout, just have to add cout.flush() after each output.

Title: Re: TProcess output to a TMemo
Post by: Edson on August 05, 2021, 08:31:28 pm
Edson -> I have modified your example because On Windows Strings must be converted from OEM to UTF8  (for latin characters ex : é )

Not problem. It's a good contribution.

I realize I need to complete some translations to English  :-\.
TinyPortal © 2005-2018