Redirect both stdout & stderr to the same file

Alex Vinokur alexvn@connect.to
Sun Jun 15 04:35:00 GMT 2003


"Igor Pechtchanski" <pechtcha@cs.nyu.edu> wrote in message news:Pine.GSO.4.44.0306141900400.25752-100000@slinky.cs.nyu.edu...
> On Sat, 14 Jun 2003, Alex Vinokur wrote:
>
> > ===========================================
> > Windows 2000
> > CYGWIN_NT-5.0 1.3.22(0.78/3/2)
> > GNU gcc version 3.2 20020927 (prerelease)
> > ===========================================
> >
> > ------ C code : BEGIN ------
> > /* File t.c */
> > #include <stdio.h>
> > int main()
> > {
> >   fprintf (stdout, "(1) to stdout\n");
> >   fprintf (stderr, "(2) to stderr\n");
> >   fprintf (stdout, "(3) to stdout\n");
> >   return 0;
> > }
> > ------ C code : END --------
> >
> > $ gcc t.c
> >
> > $ a &>zzz
> >
> > $ cat zzz
> >
> > (2) to stderr
> > (1) to stdout
> > (3) to stdout
> >
> > -----------------------
> > Expected :
> > (1) to stdout
> > (2) to stderr
> > (3) to stdout
> > -----------------------
> >
> > What is wrong?
>
> Buffering.  stdout is buffered, stderr isn't.  Try adding "fflush(stdout)"
> after the first fprintf.  This is a basic C stdio question, it'll work the
> same way on Linux, FYI.
[snip]

Thanks.

Something else.
It seems that cerr isn't buffered.

===========================================
Windows 2000
CYGWIN_NT-5.0 1.3.22(0.78/3/2)
GNU gcc/g++ version 3.2 20020927 (prerelease)
===========================================

--------- C++ code : BEGIN ---------
// File t.cpp
#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
  fprintf (stdout, "(01) to stdout\n");
  fprintf (stderr, "(02) to stderr\n");

  fprintf (stdout, "(03) to stdout\n");
  fprintf (stderr, "(04) to stderr\n");

  cout << "(05) to cout" << endl;
  cerr << "(06) to cerr" << endl;
  clog << "(07) to clog" << endl;

  cout << "(08) to cout" << endl;
  cerr << "(09) to cerr" << endl;
  clog << "(10) to clog" << endl;

  fprintf (stdout, "(11) to stdout\n");
  fprintf (stderr, "(12) to stderr\n");

  cout << "(13) to cout" << endl;
  cerr << "(14) to cerr" << endl;
  clog << "(15) to clog" << endl;

  return 0;
}

--------- C++ code : END -----------


--------- Run Log : BEGIN ---------

$ g++ t.cpp

$ a 2>&1 | more
(02) to stderr
(04) to stderr
(01) to stdout
(03) to stdout
(05) to cout
(06) to cerr
(07) to clog
(08) to cout
(09) to cerr
(10) to clog
(12) to stderr
(11) to stdout
(13) to cout
(14) to cerr
(15) to clog

--------- Run Log : END -----------


   ==========================================
   Alex Vinokur
     mailto:alexvn@connect.to
     http://www.simtel.net/pub/oth/19088.html
     http://sourceforge.net/users/alexvn
   ==========================================






--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list