How to “tee” stderr


So, I want to capture the standard error to the log file.

The post below was by pfiynn, from the http://www.unix.com forum:

If your shell is Bash or similar, this set of redirections will do the job


command 3>&1 1>&2 2>&3 | tee file

What does it mean?

The redirection operator n>&m, makes file descriptor n to be a copy of file descriptor m.

So, we are:

– Opening a new file descriptor, 3, that is a copy of file descriptor 1, the standard output;

– Making file descriptor 1 a copy of file descriptor 2, the standard error output;

– Making file descriptor 2 to be a copy of file descriptor 3 the “backup” of the standard outputin a short: we swapped the standard output and the standard error output.

via How to “tee” stderr – The UNIX and Linux Forums.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s