Recent

Author Topic: TProcess a executable line by line  (Read 5775 times)

pascalbythree

  • Full Member
  • ***
  • Posts: 119
TProcess a executable line by line
« on: October 09, 2021, 09:27:56 pm »
Anybody got example code to TProcess a executable and then copy eatch apeard line in a string, line by line?, Greetz Wouter

MarkMLl

  • Hero Member
  • *****
  • Posts: 5540
Re: TProcess a executable line by line
« Reply #1 on: October 09, 2021, 09:34:37 pm »
Is this intended as a continuation of your https://forum.lazarus.freepascal.org/index.php/topic,56655.msg421124.html#msg421124 ?

This isn't IRC, and I'd suggest that once you've started a thread it is appropriate to wait for responses (and to answer people who ask for clarification).

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Edson

  • Hero Member
  • *****
  • Posts: 1252
Re: TProcess a executable line by line
« Reply #2 on: October 09, 2021, 11:28:10 pm »
You can use: https://github.com/t-edson/UnTerminal

Then capture the output line by line using:

Code: Pascal  [Select][+][-]
  1.   proc := TConsoleProc.Create(nil);
  2.   proc.OnLineCompleted:=@procOnLineCompleted;
  3.   proc.Open('cmd /c dir','');
  4.  
  5. ...
  6.  
  7. procedure TForm1.procOnLineCompleted(const lin: string);
  8. begin
  9.   Memo.Lines.Add(lin);
  10. end;
Lazarus 2.0.10 - FPC 3.2.0 - x86_64-win64 on Windows 8

pascalbythree

  • Full Member
  • ***
  • Posts: 119
Re: TProcess a executable line by line
« Reply #3 on: October 10, 2021, 05:37:53 pm »
This is 100% procent where i am looking for, UnTerminal-1.0

except its seems to be only to work in lazarus GUI

Do you know  a software package similar for the RaspBian LITE version?

Because it only has to be to work in the console, without GUI.


Edson

  • Hero Member
  • *****
  • Posts: 1252
Re: TProcess a executable line by line
« Reply #4 on: October 10, 2021, 06:17:00 pm »
except its seems to be only to work in lazarus GUI

Do you know  a software package similar for the RaspBian LITE version?

Because it only has to be to work in the console, without GUI.

Check the Example3 project in the Github. It's a console application.

If you don't want to include the LCL dependency, remove the references to TPanel or TTimer in the library. In this case you can use the functions: RunInLoop() to control a process.
Lazarus 2.0.10 - FPC 3.2.0 - x86_64-win64 on Windows 8

pascalbythree

  • Full Member
  • ***
  • Posts: 119
Re: TProcess a executable line by line
« Reply #5 on: October 10, 2021, 09:00:07 pm »
Only seems to work while xwindows is running. Are you sure it is possible if booted to the command line?

Edson

  • Hero Member
  • *****
  • Posts: 1252
Re: TProcess a executable line by line
« Reply #6 on: October 10, 2021, 11:28:25 pm »
I've tested in Linux and Windows. In command line only in Windows. I don't know what process are you trying to control.
Lazarus 2.0.10 - FPC 3.2.0 - x86_64-win64 on Windows 8

pascalbythree

  • Full Member
  • ***
  • Posts: 119
Re: TProcess a executable line by line
« Reply #7 on: October 11, 2021, 01:50:53 pm »
Just trying to start Avrdude on a Raspberry lite
then line by line in my fpc console application

So if i may repeat a little, not possible without a linux GUI ?

Thanks.
« Last Edit: October 11, 2021, 01:55:06 pm by pascalbythree »

MarkMLl

  • Hero Member
  • *****
  • Posts: 5540
Re: TProcess a executable line by line
« Reply #8 on: October 11, 2021, 02:14:31 pm »
Just trying to start Avrdude on a Raspberry lite
then line by line in my fpc console application

See the thread you started before. I asked you a couple of specific questions, and you didn't bother to answer.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

prof7bit

  • Full Member
  • ***
  • Posts: 159
Re: TProcess a executable line by line
« Reply #9 on: October 11, 2021, 03:55:03 pm »
answered with a code snippet in your other thread

bills

  • New Member
  • *
  • Posts: 40
Re: TProcess a executable line by line
« Reply #10 on: September 18, 2022, 09:24:37 am »
I've tested in Linux and Windows. In command line only in Windows. I don't know what process are you trying to control.
Thank you Edson. I download the UnTerminal-1.0.
When I compile and run the example, first click the start button(the command text is: CMD), sencond click the Send button(the command text is dir), then the application give the message: Error setting stream size.
My os is windows10.



Edson

  • Hero Member
  • *****
  • Posts: 1252
Re: TProcess a executable line by line
« Reply #11 on: September 18, 2022, 07:36:19 pm »
Thank you Edson. I download the UnTerminal-1.0.
When I compile and run the example, first click the start button(the command text is: CMD), sencond click the Send button(the command text is dir), then the application give the message: Error setting stream size.
My os is windows10.

Hi. It seems something has changed in Lazarus LCL recently. Now I cannot set: TProcess.Input.Size. I had to comment that part in the library. Now is working. Repository in Github has been updated.
Lazarus 2.0.10 - FPC 3.2.0 - x86_64-win64 on Windows 8

bills

  • New Member
  • *
  • Posts: 40
Re: TProcess a executable line by line
« Reply #12 on: September 20, 2022, 04:23:30 pm »
Thanks Edson. Now the program is run ok.

rvk

  • Hero Member
  • *****
  • Posts: 5007
Re: TProcess a executable line by line
« Reply #13 on: September 20, 2022, 04:32:09 pm »
Anybody got example code to TProcess a executable and then copy eatch apeard line in a string, line by line?, Greetz Wouter
You already got this code from the other topic:
Code: Pascal  [Select][+][-]
  1. if RightStr(Line, Length(LineEnding)) = LineEnding then begin;
  2.   Line := Trim(Line);
  3.   Print(Line); // ----> This is a completed string
  4.   Line := '';
  5. end;
Line 3 (and after line 5) has a completed string in Line variable each time (so 'line by line').
So what more (or else) do you want?

 

TinyPortal © 2005-2018