[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: BASH Redirect (STDOUT & STDERR) Syncing



On Tue, 2005-04-12 at 14:57 +0200, Bruno Hertz wrote:
> michael <linux@networkingnewsletter.org.uk> writes:
> 
> > On Tue, 2005-04-12 at 05:09 +0200, Bruno Hertz wrote:
> >> Hal Vaughan <hal@thresholddigital.com> writes:
> >> 
> >> > I'm running a Perl script and redirecting the output to a file, and 
> >> > redirecting STDERR to the same file, like this:
> >> >
> >> > myprog >capture.txt 2>&1
> >> >
> >> > And I've noticed that the error output is not in sync with STDOUT.  Is there 
> >> > any way, when doing a redirect like this, to synchronize the output, so I can 
> >> > tell when (in relation to STDOUT) the error messages were output?
> >> 
> >> Hey
> >> 
> >> this is a wild guess coming now, but I'm posting it just to compare it
> >> to what finally comes out as being right.
> >> 
> >> They aren't 'in sync', as you call it, presumably because of the
> >> output buffering done in Perl, where one channel, either stdout or
> >> stdin, receives significant less output than the other and hence
> >> flushes more seldom.
> >
> > Actually, I've noticed this for many things I've run from the cmd line
> > in Debian (and have noticed it not happening for other Unices)... the
> > only thing that springs to mind at the moment is output from 'make'
> > having std err and std out well out of sync.... any ideas what might be
> > going on here? (Debian GNU/Linux, 2.4.27-1-686-smp, Sarge apt updates)
> 
> Hmmm, not sure I can confirm this. Especially with command line tools
> it's common practice to do line buffering when output is directed to a
> terminal and block buffering otherwise, e.g. in pipes or when output
> is redirected into a file.
> 
> Especially regarding block buffering, if a program doesn't take extra
> measures it's buffering strategy will usually be governed by the
> standard library, i.e. glibc. And in that case the only possible
> reason for differing behavior on different platforms could only be
> some config option given to glibc, presumably during compilation time,
> targeting e.g. the buffer size. This may be possible, but at least I'm
> not aware of Debian doing something special in that regard and can't
> myself really say that Sarge behaves any different than, say, FC3.
> 
> Maybe somebody else knows more ?
> 
> Regards, Bruno.
> 

okay, a quick try to recreate this failed, so let me try another time
when less busy. it may be that I did something silly like a parallel
compile in which case I'd expect a bit of a mess in the make-log for
  make -j 2 > make-log 2>&1
sort of thing

NB: I was comparing outputs with not just other Linux dists but IRIX too




-- 
Michael Bane
Atmospheric Physics Group
University of Manchester



Reply to: