Sign in Join

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

Mailing lists / fpc-pascal / 2003-09

CR / CRLF problem when redirecting to file

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

John Coppens

Hello all,

In Linux, when redirecting FPC output to a file, I found that after 25 lines, CR characters are being added, as if in DOS:

program TestCR;
uses
  CRT;
var
  i: integer;
begin
  for i := 1 to 50 do
    writeln('The quick brown fox jumps over the lazy dog''s back ', i);
end.

when doing a ./testcr > testcr.txt

CR's appear on line 25 and after. (This seems to profoundly confuse some terminal windows, which change mode and have to be 'reset').

John

Reply by email

James Mills
to John Coppens
John Coppens wrote 19 lines
Hello all, In Linux, when redirecting FPC output to a file, I found that after 25 lines, CR characters are being added, as if in DOS: program TestCR; uses CRT; var i: integer; begin for i := 1 to 50 do writeln('The quick brown fox jumps over the lazy dog''s back ', i); end. when doing a ./testcr > testcr.txt CR's appear on line 25 and after. (This seems to profoundly confuse some terminal windows, which change mode and have to be 'reset').

Yes this happens all the time when dealing with stdin and stdout with FPC. I'm not sure why either :) Log files can sometimes get really ugly with CRLF's appearing where they shouldn't be (seeing as it's linux not msdos)

Perhaps it's a bug ?

cheers
James

- -Zero Defect Software Engineers Group - ZDSEG - -You need only two tools. WD-40 and duct tape. -If it doesn't move and it should, use WD-40. -If it moves and shouldn't, use the tape.

Reply by email

Jonas Maebe
to John Coppens: In Linux, when redirecting FPC output to a file, I found that after 25 lines, CR…
John Coppens wrote 6 lines
In Linux, when redirecting FPC output to a file, I found that after 25 lines, CR characters are being added, as if in DOS: program TestCR; uses CRT;

That's because you are using the crt unit. The crt unit is only meant for screen display, it has to use all sorts of tricks on a *nix console (setting it to raw mode, for instance). That's why you get garbage if you redirect it to a file.

Jonas

Reply by email

John Coppens
to Jonas Maebe
Show quoted text 7 lines
That's because you are using the crt unit. The crt unit is only meant for screen display, it has to use all sorts of tricks on a *nix console (setting it to raw mode, for instance). That's why you get garbage if you redirect it to a file. Jonas

Hello Jonas.

Is there no elegant solution to this? I use a library of mine that does some screen operations, like gotoxy, and includes the CRT library. So, even if I only use hex output from that library, I still get CRT for free. I could seperate those routines, but that CRT library would always dangle there as a Damocles's sword...

I'm no expert - doesn't the forms library do something similar as the crt library?

John

Reply by email

Jonas Maebe
to John Coppens
John Coppens wrote 7 lines
Is there no elegant solution to this? I use a library of mine that does some screen operations, like gotoxy, and includes the CRT library. So, even if I only use hex output from that library, I still get CRT for free. I could seperate those routines, but that CRT library would always dangle there as a Damocles's sword...

No, the problem is that the CRT unit has to change the settings of console to be able to do everything you expect from it. You can do this:

uses
   crt;
var
   t: text;
begin
   assign(t,'');
   rewrite(t);
   writeln(t,'This goes to stdout without passing through the crt unit');
end.

but the console is still in raw mode then and you will still get mangled output in some cases (or maybe get wrong output on screen instead of on disk). Maybe using ncrt instead of crt may help, I don't know.

I'm no expert - doesn't the forms library do something similar as the crt library?

I don't know the forms unit, I've never worked with it.

Jonas

Reply by email

James Mills
to Jonas Maebe: That's because you are using the crt unit. The crt unit is only meant for screen display,…
Jonas Maebe wrote 14 lines
On zondag, sep 14, 2003, at 17:48 Europe/Brussels, John Coppens wrote: >In Linux, when redirecting FPC output to a file, I found that after 25 >lines, CR characters are being added, as if in DOS: > >program TestCR; >uses > CRT; That's because you are using the crt unit. The crt unit is only meant for screen display, it has to use all sorts of tricks on a *nix console (setting it to raw mode, for instance). That's why you get garbage if you redirect it to a file.

In some of my programs I do NOT use the CRT unit but a similar thing happens. Go figure :)

cheers
James

- -Zero Defect Software Engineers Group - ZDSEG - -You need only two tools. WD-40 and duct tape. -If it doesn't move and it should, use WD-40. -If it moves and shouldn't, use the tape.

Reply by email

John Coppens
to James Mills
In some of my programs I do NOT use the CRT unit but a similar thing happens. Go figure :)

Hi James... I didn't have crt in my program, but called another unit that did have it. So the danger is always present ;-)

Reassigning assign(f, ''); works for directing to a file, but the output on the screen doesn't work.

Will have a look at nCRT...

Cheers,
John

Reply by email