Skip to content. | Skip to navigation

Navigation

You are here: Home / Support / Guides / Scripting / Bash / Redirecting stdout/stderr / The Solution

Personal tools

Redirecting stdout/stderr

Redirecting stdout and stderr to a file and have stdout and stderr available to redirect as normal.

The Solution

Here's how to redirect stdout and stderr to a file and have stdout and stderr on their original streams for any calling process to redirect as it sees fit:

exec 3>&1 4>&2
(
 cmd args > >(tee /dev/fd/3) 2> >(tee /dev/fd/4 >&2)
) > file 2>&1

The following pages tell you why this works and why other solutions don't.

Document Actions