c - Instant redirect program output to file without buffering from batch file -
i have c
program messages printed printf
command. batch file call program with
call myprogram.exe parms > myfile.txt
i need myfile
updated every time (or every time) when myprogram
print message. now, cannot see in file until program finish execution, because buffering. buffering problem c
program, batch file
or operating system, , how can resolve it?
stdio.h
functions buffering. see setvbuf. buffering may operating system specific, , may change when redirecting (e.g. because internally isatty(3) used inside printf
etc...).
notice buffering useful, , speeds output lot.
the simplest way call fflush(3) time time. otherwise call setvbuf
_iofbf
on stdout
.
using setvbuf
near start of program simpler. however, calling fflush
@ appropriate places might more efficient (because using larger buffer should faster).
Comments
Post a Comment