Am 18.07.2016 15:59, schrieb Greg Wooledge:
> On Mon, Jul 18, 2016 at 10:22:46AM +0200, walter harms wrote:
>>  ( ./a.out 2>&1 )
>> hallo 5
>> hallo 6
>> hallo 7
>> hallo 8
>> hallo 9
> 
> (snip)
> 
>> ./a.out  >xx 2>&1
>>  cat xx
>> hallo 6
>> hallo 8
>> hallo 5
>> hallo 7
>> hallo 9
> 
> Looks like an artifact of stdio (libc) buffering.  When stdout and
> stderr are going to a terminal (first example), you get line buffering
> (flushed after each newline), and thus the order you expect.  When stdout
> and stderr are going to a file, you get much larger buffers.  Looks like
> the flush happens implicitly when the program exits.  In your second
> example here, you happen to get all of the stderr lines first, followed
> by all of the stdout lines.
> 
> See if the behavior changes when you add these lines to the start of
> the C program:
> 
> setvbuf(stdout, NULL, _IOLBF, 0);
> setvbuf(stderr, NULL, _IOLBF, 0);

thx for the fast reply, my testprogramm works as expected after the changes.

My basic mistake was that my understand was that \n should flush the buffer,
that was obviously wrong.

NTL i would recommend to add one or two line about buffering into
    the ducomentation :)

thx for help,

re,
 wh




Reply via email to