[fpc-pascal] Writeln() behaves differently on Windows and Linux, why?

Sven Barth pascaldragon at googlemail.com
Thu Jul 9 23:44:33 CEST 2020


Am 09.07.2020 um 18:42 schrieb Bo Berglund via fpc-pascal:
> On Thu, 9 Jul 2020 16:25:50 +0000, Alexander Grotewohl
> <alex at dcclost.com> wrote:
>
>> it sounds like your terminal has gotten fudged somehow
>>
> I am using crt in the lpr file just for the sake of being able to shut
> it down sensibly:

It doesn't matter where the CRT unit is used. It hooks globally for the 
whole program.

>
>    try
>      RemoteSrv.ClientPort := 23500; //Set port explicitly
>      Logger.StdLog('Starting remote server on port: ' +
> IntToStr(RemoteSrv.ClientPort));
>      Writeln('Starting remote server on port: ' +
> IntToStr(RemoteSrv.ClientPort));
>      RemoteSrv.StartServer;
>      Writeln('Server running, hit q to exit!');
>      repeat
>        ch := ReadKey;  <== NEEDS unit crt to read the keypress
>      until ch='q'; {q}
>      Writeln('Shutting down server');
>      Logger.StdLog('Shutting down server');
>      RemoteSrv.StopServer;
>    finally
>      RemoteSrv.Free;
>    end;
>    Writeln('Terminating program');
>
> The messages put out from this code are all left aligned.
>  From then on the messages are stacked sideways but on a new line.
>
> So when the server (it is a TCP/IP socket server) gets a client call
> this is written in the console by the writeln() executed inside the
> handler as I showed in my start message.
>
> I have tried the Linux terminal on Raspbian Buster and from Windows
> PuTTY, both show the same strange behaviour.
>
> If I run the program on Windows this does not happen (same code just
> compiled on Windows or Linux).

You could try to use CheckSynchronize(SomeLowTimeout) inside the main 
loop (together with KeyPressed before using ReadKey) and then do your 
other output in the Indy event handlers using TThread.Synchronize or 
TThread.Queue.

Regards,
Sven


More information about the fpc-pascal mailing list