Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2019-10

Lazarus program runs fine in a Terminal but not in a PuTTY session, why?

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I am working on a program intended to be run by cron in unattended mode on a Raspberry Pi without GUI installed.

I started it in Windows but have now moved the sources over to Raspbian for building on that platform and it does not work as expected...

If I open a terminal window inside the Raspbian GUI (I am using VNC to work in the GUI) then the test run works as expected.

Right now it is just displaying the content of the directory where the data will be located using this code as a test:

function TaskReadyToRun(var ID: string): boolean;
var
  FileList: TStringList;
  TaskDir: string;
  i: integer;
begin
  FileList := TStringList.Create;
  try
    TaskDir := DATABASEDIR + '/tasks';
    FindAllFiles(FileList, TaskDir, '*.conf', false);
    if FileList.Count > 0 then
    begin
      for i := 0 to FileList.Count -1 do
        Writeln(FileList[i]);
    end
    else
      Writeln('No files found');
    Result := (FileList.Count > 0);
  finally
    FileList.Free;
  end;
end;

In a termional window on Raspbian I get the expected output.

But when I run the same in a terminal created by PuTTY on my Windows laptop this is what I see:

pi at rpi4-gui:~/projects/MonitorServer $ ./ssmonitorctrl

(ssmonitorctrl:5436): Gtk-WARNING **: 10:43:42.775: cannot open display:

Even if I run the program and redirect output to a file I get the same error message and the listfiles.txt file is empty:

pi at rpi4-gui:~/projects/MonitorServer $ ./ssmonitorctrl > listfiles.txt

What is causing this strange problem?

I thought that Writeln() is the way to send output to stdout, but maybe not????

Bo Berglund Developer in Sweden

Reply by email

Bo Berglund
to Bo Berglund
Bo Berglund wrote 7 lines
I am working on a program intended to be run by cron in unattended mode on a Raspberry Pi without GUI installed. I started it in Windows but have now moved the sources over to Raspbian for building on that platform and it does not work as expected...

After posting here I went into project options and looked for something that could relate to the GUI being present and then I found this:

Project/ProjectOptions/CompilerOptions/AdditionsAndOverrides/SetLCLWidgetType/

Here was a selection "nogui", which I set and now the error disappeared!!!

Hard to find but seems like I am OK for now...

Bo Berglund Developer in Sweden

Reply by email

Michael Van Canneyt
to Bo Berglund
Bo Berglund wrote 21 lines
On Thu, 31 Oct 2019 11:06:17 +0100, Bo Berglund via lazarus wrote: > I am working on a program intended to be run by cron in unattended > mode on a Raspberry Pi without GUI installed. > > I started it in Windows but have now moved the sources over to > Raspbian for building on that platform and it does not work as > expected... > After posting here I went into project options and looked for something that could relate to the GUI being present and then I found this: Project/ProjectOptions/CompilerOptions/AdditionsAndOverrides/SetLCLWidgetType/ Here was a selection "nogui", which I set and now the error disappeared!!! Hard to find but seems like I am OK for now...

You can't run a Linux LCL graphical program through putty, unless you have an X session running on your windows machine, and you set up the necessary port forwarding.

What you did in the options is simply completely disable the GUI. As a result, the linux program does not try to connect to the X server.

If the program works 100%, you should ask yourself why you needed the GUI routines in the first place ?

Michael.

Reply by email

Bo Berglund
to Michael Van Canneyt
Michael Van Canneyt wrote 36 lines
On Thu, 31 Oct 2019, Bo Berglund via lazarus wrote: > On Thu, 31 Oct 2019 11:06:17 +0100, Bo Berglund via lazarus > wrote: > >> I am working on a program intended to be run by cron in unattended >> mode on a Raspberry Pi without GUI installed. >> >> I started it in Windows but have now moved the sources over to >> Raspbian for building on that platform and it does not work as >> expected... >> > > After posting here I went into project options and looked for > something that could relate to the GUI being present and then I found > this: > > Project/ProjectOptions/CompilerOptions/AdditionsAndOverrides/SetLCLWidgetType/ > > Here was a selection "nogui", which I set and now the error > disappeared!!! > > Hard to find but seems like I am OK for now... You can't run a Linux LCL graphical program through putty, unless you have an X session running on your windows machine, and you set up the necessary port forwarding. What you did in the options is simply completely disable the GUI. As a result, the linux program does not try to connect to the X server. If the program works 100%, you should ask yourself why you needed the GUI routines in the first place ? Michael.

I do *not* have *any* GUI routines or such.
The program was created as one of the console types Lazarus offers (I do not really know the difference between them and I don't remember which one I chose).
So it is *not* a GUI program at all, it was meant from the start to be run from cron invisible from the user rather like a service.

I also set the dependencies to LCLbase to avoid the GUI part.

Bo Berglund Developer in Sweden

Reply by email

Michael Van Canneyt
to Bo Berglund
Bo Berglund wrote 11 lines
> If the program works 100%, you should ask yourself why you needed the GUI > routines in the first place ? > > Michael. I do *not* have *any* GUI routines or such. The program was created as one of the console types Lazarus offers (I do not really know the difference between them and I don't remember which one I chose). So it is *not* a GUI program at all, it was meant from the start to be run from cron invisible from the user rather like a service.

OK.

I also set the dependencies to LCLbase to avoid the GUI part.

Well, clearly there is still a dependency on a GUI unit because the program tried to make contact with an X server.

If the 'interfaces' unit is in the uses clause of your program, try removing it.

Michael.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt

Hi Bo,

Michael Van Canneyt wrote
If the 'interfaces' unit is in the uses clause of your program, try removing it.

In addition to what Michael said, you can also run `ldd /path/and/program` and Linux will tell you your executable is dependent on X11 libraries. If so, then "nogui" might still be pulling in dependencies without your knowledge.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Bo Berglund
to Graeme Geldenhuys
Graeme Geldenhuys wrote 11 lines
Hi Bo, On 31/10/2019 10:02 pm, Michael Van Canneyt via lazarus wrote: > If the 'interfaces' unit is in the uses clause of your program, try > removing it. In addition to what Michael said, you can also run `ldd /path/and/program` and Linux will tell you your executable is dependent on X11 libraries. If so, then "nogui" might still be pulling in dependencies without your knowledge.

Does this mean that the program may still only run on a Pi where there is an installed desktop? For example if I move the application to an RPi4 with Raspbian Lite installed, will it possibly barf at me then?

With nogui it so far seems to work OK, but I have only tested very little.

Bo Berglund Developer in Sweden

Reply by email