PRB: stdout/stderr May Not Be In Sync When Using RedirectionLast reviewed: July 25, 1997Article ID: Q122442 |
The information in this article applies to:
SYMPTOMSWhen the standard output and error streams are redirected or piped, console application output may not be serialized. This can result in unexpected output.
CAUSEAlthough devices as serialized by default, the current Microsoft CRT implementation does not treat pipes as if they were devices (due to the potentially high overhead--added code--of doing so.) Thus, if stderr and stdout refer to the same file or device, and output is redirected with a pipe, the output will not be serialized.
STATUSThis behavior is by design. The potential for slow execution currently outweighs the effort necessary to implement pipes such that they are treated as devices.
MORE INFORMATIONTo demonstrate this behavior, build and run the sample code (TEST.C) below. If it is executed from an MS-DOS or Windows NT command prompt, the following output is generated:
c:\>test hello world (stdout) hello world (stderr) hello world (stdout) hello world (stderr)However, if the output is piped with the MORE command, it will not be serialized, as follows:
c:\>test | more hello world (stderr) hello world (stderr) hello world (stdout) hello world (stdout) Sample Code
/* Compile options needed: none /* /* TEST.C */ #include <stdio.h> int main(void) { printf ( "Hello world (stdout)\n" ); fprintf ( stderr, "Hello world (stderr)\n" ); printf ( "Hello world (stdout)\n" ); fprintf ( stderr, "Hello world (stderr)\n" ); } Keywords : CRTIss Version : 1.5 1.51 2.0 2.1 4.0 5.0 Platform : NT WINDOWS Issue type : kbprb |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |