Recent

Author Topic: Free Pascal / Free Vision: Executing shell commands and showing output  (Read 1579 times)

Aruna

  • Hero Member
  • *****
  • Posts: 814
Hello,

I’ve recently started exploring the Free Pascal source tree and digging into the fp text-mode IDE to better understand how things are structured and implemented. As a learning exercise, I put together a very simple Free Vision program that runs lsblk -S and displays the output in a scrollable TListBox.

The attached screenshot shows the issue I’m running into with the displayed output. I’m clearly missing something fundamental here, and I’d appreciate any pointers in the right direction.

Would this also be an appropriate question to raise on the fpc-devel list?

Thanks in advance.

cdbc

  • Hero Member
  • *****
  • Posts: 2870
    • http://www.cdbc.dk
Re: Free Pascal / Free Vision: Executing shell commands and showing output
« Reply #1 on: January 27, 2026, 12:06:14 pm »
Hi Aruna
You know there are unicode-versions of free-vision units...
They start with an 'u' like 'uviews.pas'...
Maybe that's your problem... %)

Ps.: How did you fare with the other project?
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12955
  • FPC developer.
Re: Free Pascal / Free Vision: Executing shell commands and showing output
« Reply #2 on: January 27, 2026, 12:43:55 pm »
Also unix tools might use hard tabs characters (#9) that won't work in visual controls (text or gui).

Also, while for very short output like this it probably doesn't matter, it is better to use runcommand() to properly wrap TProcess, and don't use the so called simple example.


tetrastes

  • Hero Member
  • *****
  • Posts: 769
Re: Free Pascal / Free Vision: Executing shell commands and showing output
« Reply #3 on: January 27, 2026, 03:24:58 pm »
The problem is that FreeVision is based on Objects, and you mix them with Classes. You cannot do this, at least for FV.
The following works, using Text file for simplicity:
Code: Pascal  [Select][+][-]
  1. uses
  2.   Unix,
  3.   Objects, App, Drivers, Views, Menus, Dialogs;
  4.   //Process, Classes, SysUtils;
  5.  
  6. .
  7. .
  8. .
  9.  
  10. procedure ShowTextListDialog(const Title: string);
  11. var
  12.   D: PDialog;
  13.   R: Objects.TRect;
  14.   LB: PListBox;
  15.   Lines: PStringCollection;
  16.  
  17.   f: text;
  18.   s: string;
  19. begin
  20.   R.Assign(5, 2, 75, 22);
  21.   D := New(PDialog, Init(R, Title));
  22.   if D = nil then Exit;
  23.  
  24.   Lines := New(PStringCollection, Init(100, 10));
  25.  
  26.     fpSystem('/bin/lsblk -S > lsblk.txt');
  27.     Assign(f, 'lsblk.txt');
  28.     Reset(f);
  29.     while not EOF(f) do
  30.     begin
  31.         readln(f, s);
  32.         Lines^.Insert(NewStr(s));
  33.     end;
  34.     Close(f);
  35.  
  36.   R.Assign(2, 2, 68, 17);
  37.   LB := New(PListBox, Init(R, 1, nil));
  38.   LB^.NewList(Lines);
  39.   D^.Insert(LB);
  40.  
  41.   R.Assign(30, 18, 44, 20);
  42.   D^.Insert(New(PButton, Init(R, '~O~K', cmOK, bfDefault)));
  43.  
  44.   Desktop^.ExecView(D);
  45.   Dispose(Lines, Done);
  46.   Dispose(D, Done);
  47. end;
« Last Edit: January 27, 2026, 03:35:48 pm by tetrastes »

Lutz Mändle

  • Jr. Member
  • **
  • Posts: 99
Re: Free Pascal / Free Vision: Executing shell commands and showing output
« Reply #4 on: January 27, 2026, 05:59:16 pm »
The problem is the unit SysUtils, if the uses clause looks like this:
Code: Pascal  [Select][+][-]
  1. uses
  2.   SysUtils,
  3.   Objects, App, Drivers, Views, Menus, Dialogs,
  4.   Process, Classes;
  5.  

it is working.

cdbc

  • Hero Member
  • *****
  • Posts: 2870
    • http://www.cdbc.dk
Re: Free Pascal / Free Vision: Executing shell commands and showing output
« Reply #5 on: January 27, 2026, 06:20:21 pm »
Hi
@Lutz: Good catch mate =^  8)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12955
  • FPC developer.
Re: Free Pascal / Free Vision: Executing shell commands and showing output
« Reply #6 on: January 27, 2026, 06:39:36 pm »
Probably because objects and sysutils have newstr.  Changing to "objects.newstr" might also help.

Lutz Mändle

  • Jr. Member
  • **
  • Posts: 99
Re: Free Pascal / Free Vision: Executing shell commands and showing output
« Reply #7 on: January 27, 2026, 06:56:44 pm »
Probably because objects and sysutils have newstr.  Changing to "objects.newstr" might also help.

That's it.

Aruna

  • Hero Member
  • *****
  • Posts: 814
Re: Free Pascal / Free Vision: Executing shell commands and showing output
« Reply #8 on: January 28, 2026, 06:00:57 pm »
Hi Aruna
You know there are unicode-versions of free-vision units...
They start with an 'u' like 'uviews.pas'...
Maybe that's your problem... %)

Ps.: How did you fare with the other project?
Regards Benny
Hi Benny, it looks like in my installation I do not have the unicode versions. See attached picture.  Where do I find the unicode-versions? And the other project I did get started but then life happened as in a fire on the third floor of the hospital I volunteer at and right now we have a full white-out and highest snow fall ever recorded in Toronto. So I will get back to your code but when I have no clue. Too much happening right now that requires my atttention. You know it is funny I thought once retired and a senior citizen life will slow down, exact opposite actually.  :)

Aruna

  • Hero Member
  • *****
  • Posts: 814
Re: Free Pascal / Free Vision: Executing shell commands and showing output
« Reply #9 on: January 28, 2026, 06:04:33 pm »
Also unix tools might use hard tabs characters (#9) that won't work in visual controls (text or gui).

Also, while for very short output like this it probably doesn't matter, it is better to use runcommand() to properly wrap TProcess, and don't use the so called simple example.
Thank you marcov. It is just that I like the control TProcess gives me as in full control over execution. But I will use Runcommand() and see..
« Last Edit: January 28, 2026, 06:17:51 pm by Aruna »

Aruna

  • Hero Member
  • *****
  • Posts: 814
Re: Free Pascal / Free Vision: Executing shell commands and showing output
« Reply #10 on: January 28, 2026, 06:05:33 pm »
The problem is that FreeVision is based on Objects, and you mix them with Classes. You cannot do this, at least for FV.
The following works, using Text file for simplicity:
Code: Pascal  [Select][+][-]
  1. uses
  2.   Unix,
  3.   Objects, App, Drivers, Views, Menus, Dialogs;
  4.   //Process, Classes, SysUtils;
  5.  
  6. .
  7. .
  8. .
  9.  
  10. procedure ShowTextListDialog(const Title: string);
  11. var
  12.   D: PDialog;
  13.   R: Objects.TRect;
  14.   LB: PListBox;
  15.   Lines: PStringCollection;
  16.  
  17.   f: text;
  18.   s: string;
  19. begin
  20.   R.Assign(5, 2, 75, 22);
  21.   D := New(PDialog, Init(R, Title));
  22.   if D = nil then Exit;
  23.  
  24.   Lines := New(PStringCollection, Init(100, 10));
  25.  
  26.     fpSystem('/bin/lsblk -S > lsblk.txt');
  27.     Assign(f, 'lsblk.txt');
  28.     Reset(f);
  29.     while not EOF(f) do
  30.     begin
  31.         readln(f, s);
  32.         Lines^.Insert(NewStr(s));
  33.     end;
  34.     Close(f);
  35.  
  36.   R.Assign(2, 2, 68, 17);
  37.   LB := New(PListBox, Init(R, 1, nil));
  38.   LB^.NewList(Lines);
  39.   D^.Insert(LB);
  40.  
  41.   R.Assign(30, 18, 44, 20);
  42.   D^.Insert(New(PButton, Init(R, '~O~K', cmOK, bfDefault)));
  43.  
  44.   Desktop^.ExecView(D);
  45.   Dispose(Lines, Done);
  46.   Dispose(D, Done);
  47. end;
Thank you tetrastes I never thought of writing to a text file.  :)

Aruna

  • Hero Member
  • *****
  • Posts: 814
Re: Free Pascal / Free Vision: Executing shell commands and showing output
« Reply #11 on: January 28, 2026, 06:06:35 pm »
The problem is the unit SysUtils, if the uses clause looks like this:
Code: Pascal  [Select][+][-]
  1. uses
  2.   SysUtils,
  3.   Objects, App, Drivers, Views, Menus, Dialogs,
  4.   Process, Classes;
  5.  

it is working.
Lutz Mändle  my friend you are a genius. How ever did you figure that out? Have a look at the attached picture.

cdbc

  • Hero Member
  • *****
  • Posts: 2870
    • http://www.cdbc.dk
Re: Free Pascal / Free Vision: Executing shell commands and showing output
« Reply #12 on: January 28, 2026, 06:19:05 pm »
Hi
Sorry to hear about your hospital, mate.
Right, so the u-versions comes with fpc-3.3.1, thus I've attached the 'fv' directory from 3.3.1... Have fun  ;D
Regards Benny
« Last Edit: January 28, 2026, 06:26:55 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

cdbc

  • Hero Member
  • *****
  • Posts: 2870
    • http://www.cdbc.dk
Re: Free Pascal / Free Vision: Executing shell commands and showing output
« Reply #13 on: January 28, 2026, 06:32:35 pm »
...And just to keep your spirit high  :D
I stumbled onto this today, shopping  ...just under 3$  8-)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Aruna

  • Hero Member
  • *****
  • Posts: 814
Re: Free Pascal / Free Vision: Executing shell commands and showing output
« Reply #14 on: January 28, 2026, 06:45:52 pm »
Hi
Sorry to hear about your hospital, mate.
They sorted things out fast but there is water damage so 3rd floor is still closed. But it is all good...

Right, so the u-versions comes with fpc-3.3.1, thus I've attached the 'fv' directory from 3.3.1... Have fun  ;D
Regards Benny
Thank you!

 

TinyPortal © 2005-2018