2015年11月26日木曜日 2時39分46秒 UTC+9 LCD 47:
> On 25 November 2015, Gary Johnson <[email protected]> wrote:
> > On 2015-11-25, LCD 47 wrote:
> > 
> > [...]
> > 
> > >     You can make stdout unbuffered:
> > > 
> > >         #include <stdio.h>
> > > 
> > >         int main()
> > >         {
> > >             setbuf(stdout, NULL);
> > >             printf("This is a message on stdout and should appear 
> > > first\n");
> > >             fprintf(stderr, "This is a message on stderr and should 
> > > appear second\n");
> > > 
> > >             return 0;
> > >         }
> > > 
> > > or you can flush stdout before writing to stderr:
> > > 
> > >         #include <stdio.h>
> > > 
> > >         int main()
> > >         {
> > >             printf("This is a message on stdout and should appear 
> > > first\n");
> > >             fflusf(stdout);
> > >             fprintf(stderr, "This is a message on stderr and should 
> > > appear second\n");
> > > 
> > >             return 0;
> > >         }
> > > 
> > >     But you can only do this because you can recompile the program.  If
> > > you can't change the program you're out of luck.  You can't fix the
> > > problem without changing the program itself.
> > 
> > Thanks for the explanations and clearing up my misunderstandings.
> > 
> > There may be a solution that doesn't require modifying and
> > recompiling the program:  run the program under unbuffer or stdbuf.
> > 
> > http://linux.die.net/man/1/unbuffer
> > http://linux.die.net/man/1/stdbuf
> 
>     Indeed, this works:
> 
>         unbuffer make run 2>&1 | cat
> 
> and so does this:
> 
>         stdbuf -o L make run 2>&1 | cat
> 
>     But unbuffer(1) is part of the expect package, and stdbuf(1) is
> Linux-specific.
> 
>     /lcd

Thank you for all the responses. I definitely jumped the gun here, not thinking 
carefully about buffering.

Adding an `fflush(stdout)` call between the `printf`s preserves order as 
expected.

Apologies for spamming the list here.

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui