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

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Free Pascal - Lazarus mailing list
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@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@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

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Lazarus program runs fine in a Terminal but not in a PuTTY session, why?

Free Pascal - Lazarus mailing list
On Thu, 31 Oct 2019 11:06:17 +0100, Bo Berglund via lazarus
<[hidden email]> 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...


--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Lazarus program runs fine in a Terminal but not in a PuTTY session, why?

Free Pascal - Lazarus mailing list


On Thu, 31 Oct 2019, Bo Berglund via lazarus wrote:

> On Thu, 31 Oct 2019 11:06:17 +0100, Bo Berglund via lazarus
> <[hidden email]> 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.
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Lazarus program runs fine in a Terminal but not in a PuTTY session, why?

Free Pascal - Lazarus mailing list
On Thu, 31 Oct 2019 11:26:26 +0100 (CET), Michael Van Canneyt via
lazarus <[hidden email]> wrote:

>
>
>On Thu, 31 Oct 2019, Bo Berglund via lazarus wrote:
>
>> On Thu, 31 Oct 2019 11:06:17 +0100, Bo Berglund via lazarus
>> <[hidden email]> 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

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Lazarus program runs fine in a Terminal but not in a PuTTY session, why?

Free Pascal - Lazarus mailing list


On Thu, 31 Oct 2019, Bo Berglund via lazarus wrote:

>> 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.
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Lazarus program runs fine in a Terminal but not in a PuTTY session, why?

Free Pascal - Lazarus mailing list
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.


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
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Lazarus program runs fine in a Terminal but not in a PuTTY session, why?

Free Pascal - Lazarus mailing list
On Thu, 31 Oct 2019 23:04:50 +0000, Graeme Geldenhuys via lazarus
<[hidden email]> wrote:

>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

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus