Re: [bash] Redirecting both stdout & stderr to the same file
From: Alex Vinokur (alexvn_at_bigfoot.com)
Date: 06/14/03
- Previous message: parv: "Re: Removing white spaces from filenames"
- In reply to: joe_at_invalid.address: "Re: [bash] Redirecting both stdout & stderr to the same file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Sat, 14 Jun 2003 19:08:21 +0300
<joe@invalid.address> wrote in message news:m31xxwu442.fsf@invalid.address...
> "Alex Vinokur" <alexvn@bigfoot.com> writes:
>
> > "Ed Morton" <morton@lucent.com> wrote in message news:bcf788$ift@netnews.proxy.lucent.com...
> > >
> > > "Alex Vinokur" <alexvn@bigfoot.com> wrote in message
> > > news:bcf6ph$ipdku$1@ID-79865.news.dfncis.de...
> > > > How to redirect both stdout & stderr to the same file using bash?
> > >
> > > command > file 2>&1
>
> > ===========================================
> > Windows 2000
> > CYGWIN_NT-5.0 1.3.22(0.78/3/2)
> > GNU bash, version 2.05b.0(5)-release-(i686-pc-cygwin)
> > GNU gcc version 3.2 20020927 (prerelease)
> > ===========================================
> >
> > Here is a sample code.
> >
> > ------ 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 2>&1
> >
> > $ cat zzz
> > (2) to stderr
> > (1) to stdout
> > (3) to stdout
> >
> >
> > -----------------------
> > Expected :
> > $ cat zzz
> > (1) to stdout
> > (2) to stderr
> > (3) to stdout
> > -----------------------
> >
> > What is wrong?
>
> Nothing, stderr is unbuffered, while stdout is fully buffered when
> output is redirected, so stderr output shows up first.
>
> Joe
Thanks.
By the way, cout, cerr and clog have no problem with that.
===========================================
Windows 2000
CYGWIN_NT-5.0 1.3.22(0.78/3/2)
GNU bash, version 2.05b.0(5)-release-(i686-pc-cygwin)
GNU gcc/g++ version 3.2 20020927 (prerelease)
===========================================
Here is a sample code.
------ C++ code : BEGIN ------
/* File t.cpp */
#include <iostream>
using namespace std;
int main()
{
cout << "(1) to cout" << endl;
cerr << "(2) to cerr" << endl;
clog << "(3) to clog" << endl;
cout << "(4) to cout" << endl;
cerr << "(5) to cerr" << endl;
clog << "(6) to clog" << endl;
return 0;
}
------ C++ code : END --------
$ g++ t.cpp
$ a > zzz 2>&1
$ cat zzz
(1) to cout
(2) to cerr
(3) to clog
(4) to cout
(5) to cerr
(6) to clog
==========================================
Alex Vinokur
mailto:alexvn@connect.to
http://www.simtel.net/pub/oth/19088.html
http://sourceforge.net/users/alexvn
==========================================
- Previous message: parv: "Re: Removing white spaces from filenames"
- In reply to: joe_at_invalid.address: "Re: [bash] Redirecting both stdout & stderr to the same file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|