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

Michael Van Canneyt michael at freepascal.org
Thu Jul 9 19:36:31 CEST 2020



On Thu, 9 Jul 2020, Bo Berglund via fpc-pascal wrote:

> On Thu, 9 Jul 2020 16:25:50 +0000, Alexander Grotewohl
> <alex at dcclost.com> wrote:
>
>> perhaps try 'reset' or 'stty sane' in the terminal before running your program?
>
> reset in PuTTY gives me a new resized empty screen, but works exactly
> the same afterwards.
>
>> are you using the crt or video units at all?
> Yes, see below.
>>
>> 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:
>
>  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.

Is this done in a thread ? Since you're using indy, I suppose so.

The crt unit is not thread safe. The implementation on Windows and Linux is
totally different, which may explain the difference you see.

Michael.


More information about the fpc-pascal mailing list