| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | redirection |
HdA>
> appli log
>
> leaves me with a file of 0 length, whereas without redirection:
>
> appli < input
>
> results are written to the screen.
HdA>
Somewhere in the documentation for your C++ compiler, it will say what
the buffering behaviour of the standard output stream is. To quote
from the ISO C standard :
"When opened [...] the standard input and standard output streams are
fully buffered if and only if the stream can be determined not to
refer to an interactive device."
In other words, the buffering changes according to whether the RTL can
determine whether the standard output is a device or a file. In the
former case it is a file, and the standard output is fully buffered. A
fully buffered stream doesn't empty its buffers (by calling the OS/2
DosWrite function) until the buffer is full.
In the latter case, it is an interactive device (i.e. the console), and
the standard output can be either unbuffered or line buffered. The
standard doesn't specify which. Different C++ compilers choose
different options. IBM VisualAge C++ chooses line buffering, which
means that the standard output stream buffer isn't written (via
DosWrite) until a NewLine character is written (or the buffer is full,
or other implementation-defined conditions occur).
So in the former case, if you haven't written BUFSIZ characters to
standard output before your program fails, they won't have been
actually written (via DosWrite) and will be lost.
There are three solutions :
1. Output to standard error instead (it is _never_ fully buffered).
2. Use `setvbuf' to make the standard output line buffered
unconditionally (making it unbuffered is overkill and redundant
considering that you are probably writing a whole line at a time
anyway).
3. Use `fflush' to flush the contents of the stream buffer after
every `printf' statement.
> JdeBP <
___
X MegaMail 2.10 #0:
--- Maximus/2 3.01
* Origin: DoNoR/2,Woking UK (44-1483-725167) (2:440/4)SEEN-BY: 50/99 54/99 270/101 620/243 625/160 711/401 413 430 934 712/311 407 SEEN-BY: 712/505 506 517 623 624 704 713/317 800/1 @PATH: 440/4 141/209 270/101 712/624 711/934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.