[sllug-members]: stderr + less
Chad Lake
clake at cs.utah.edu
Thu May 4 13:09:06 MDT 2006
On May 4, 2006, at 12:44 PM, Steve Dibb wrote:
> Is there a way to pipe stuff put out through stderr to less?
>
> I'm trying to do "foo | less" but with no arguments, it displays
> the help file on stderr, and I can't figure out how to page it.
The problem is that pipes work by connecting stdout to stdin, so you
have to have whatever data you want paged coming out of stdout. If
you don't care about merging the two, you can always just do "foo
2>&1 | less" and then both stdout and stderr will go to the pipe.
However, if you only want to see what's on stderr, here's a trick
that I use under bash, in a somewhat contrived example:
find . -print 2>&1 > /dev/null | less
In this instance, the 2>&1 comes *before* the "> /dev/null" part.
This means that stderr is dup'd to stdout before stdout is redirected
to /dev/null (or wherever). So, for whatever the find outputs, the
stuff spit out to stderr will wind up going to regular stdout (and to
the pipe) and the stuff spit out to stdout will go to the redirect
(in this case /dev/null).
Oh, and of course you can always do something like this:
foo 2>/tmp/errorstuff
less /tmp/errorstuff
rm /tmp/errorstuff
if you really want to keep it simple. :)
-c
More information about the sllug-members
mailing list