www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - writef / writefln and passing output to a file

reply jicman <jicman_member pathlink.com> writes:
Greetings!

Let us imagine that I have a program call prog.exe.  When I run that program I
get some output on the screen and then it goes and grabs a bunch of xml from a
server and does some things.  While grabbing all of these xml data, there is a
big pause, but nonetheless, the are headings and information printed before this
pause.  For example

<example out>
c:\> prog.exe arg1 arg2 arg3
Program Version 1.0.19
Login on to server arg1
Login on using user arg2
Date: <%date%>
Blah blah blah

Waiting for data from arg1...

</example out>

Ok, so this shows right away after running the program.  but if I run the same
command above and I want the output to go to a file, i.e.

c:\> prog.exe arg1 arg2 arg3 > out.txt

that information is kept for a while and later flushed with more data.  The
question is:

1.  Is this Windows or D?  (I know it's probably waiting for a certain amount of
bytes to write it to the file, but is this Windows or D?)  I have an idea, but I
want you smart-a-lics to take me to the promised land.

thanks,

josť
Mar 23 2005
parent reply "Walter" <newshound digitalmars.com> writes:
Output going to the console is flushed every time a \n is written. If the
output is going to a file, it is flushed whenever the default file buffer
gets filled up.

But you can force a flush by adding:
    std.c.stdio.fflush(stdout);
after a printf.
Mar 23 2005
parent reply jicman <jicman_member pathlink.com> writes:
Walter says...
Output going to the console is flushed every time a \n is written. If the
output is going to a file, it is flushed whenever the default file buffer
gets filled up.

This is the OS file buffer, right? Not D's, correct?
But you can force a flush by adding:
    std.c.stdio.fflush(stdout);
after a printf.

Yeah, but I don't use printf. :-) Ok, thanks.
Mar 24 2005
parent "Carlos Santander B." <csantander619 gmail.com> writes:
jicman wrote:
 Walter says...
 
Output going to the console is flushed every time a \n is written. If the
output is going to a file, it is flushed whenever the default file buffer
gets filled up.

This is the OS file buffer, right? Not D's, correct?
But you can force a flush by adding:
   std.c.stdio.fflush(stdout);
after a printf.

Yeah, but I don't use printf. :-) Ok, thanks.

After writef will also work. _______________________ Carlos Santander Bernal
Mar 24 2005