The rtlib uses \r\n when printing newlines to stdout, but it should use just \n. The C runtime replaces any \n by \r\n because stdout is opened in text mode, so we end up printing \r\r\n.
Main problem observed with DOS FB:
FreeBASIC/src/rtlib/dos/libfb_io_printbuff.c uses fwrite(stdout) when stdout is redirected, and it turns CRLF into CRCRLF.
--- 1.bas ---
print "a"
print "b";
--- run ---
$ fbc 1.bas
$ 1 > 1.txt
--- 1.txt ---
a<cr>
<cr><lf>
b
--- EOF ---</lf></cr></cr>
It also happens with the rtlib's runtime error messages, which are snprintf()'ed into a buffer and then fprintf()'ed to stderr, observed on DOS and also Windows.
--- 2.bas ---
dim as integer ptr p = 0
*p = 5
--- run ---
$ fbc 2.bas -exx
$ 2 > 2.txt 2>&1
--- 2.txt ---
<cr>
<cr><lf>
Aborting due to runtime error 7 (null pointer access) at line 2 of 2.bas::()<cr>
<cr><lf>
<cr>
<cr><lf>
--- EOF ---</lf></cr></cr></lf></cr></cr></lf></cr></cr>
http://www.freebasic.net/forum/viewtopic.php?t=17124
http://www.freebasic.net/forum/viewtopic.php?t=5672
As found in bug 3369993 this also happens with OPEN CONS and stdout being redirected to a file on Windows:
open cons for output as #1
print #1, ""
close #1
The runtime error messages should be fixed now:
http://fbc.git.sourceforge.net/git/gitweb.cgi?p=fbc/fbc;a=commit;h=f2c7aadce8f3d23124c4256c236a97ab585c3d43