Qbasicnews.com

Full Version: Why do FB screen output lines end in line-feed only?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Sometimes you want to run a program that sends output to the screen, but instead you want to capture this output by redirecting the output lines to a file.

If you do this with a QuickBasic program, the output lines end with a carriage-return line-feed.

However, if the program was compiled with FreeBasic, the output lines end with only a line-feed.

Why?

*****
I can't believe no one has any ideas about this.

Let me be more specific about how this anomaly occurs.
Write a very simple program, like
Code:
print "111"
print "222"
print "333"
Let's call the program QBTEST.BAS
Now, compile it with QuickBasic or Qbasic.
Then run it from the commandline and redirect output to QQQ, like so:
QBTEST >QQQ

Now copy QBTEST.BAS to FBTEST.BAS
Compile it with FBC.
Run as follows:
FBTEST >FFF

You can see immediately that files QQQ and FFF have different lengths.
Looking at the files with a hex editor you will notice that the 3 records produced by QBTEST are each terminated by a carriage-return and a line-feed, but those by FBTEST are only terminated by a single line-feed.

I saw something similar when I was programming in C, whereby output records only ended in a linefeed. When you run FBTEST, my compiled version is for running under Windows. Either outputting to the screen in Windows, or maybe the redirection under Windows, works differently.

Any ideas, guys?
*****
you're probably running this in Windows XP or Server :-). before (windows ME and before, probably 2000 too not sure) I don't believe there would be such a difference....but it doesn't really make a difference per se as long as it works ;-)
this shouldn't be a critical difference, however if you really need the outputs to match, change
Code:
print "111"
print "222"
print "333"
to
Code:
option escape
print "111\r"
print "222\r"
print "333\r"
Your right, Dumbledore,

Compiled with FBC, the following:
option escape
print "111\r"
print "222\r"
print "333\r"

does put carrriage-return and line-feed on the end of each record.

But, how are we supposed to know that?
*****
FB outputs CR+LF with PRINT and WRITE, now file redirection is controlled by the OS, nothing can be done about that.
Quote:FB outputs CR+LF with PRINT and WRITE, now file redirection is controlled by the OS, nothing can be done about that.
That makes sense, thanks.
*****