2

I've seen things like

command > out.txt

Sometimes appended with

2&1

But these seem to divert all output or all error streams instead of both displaying and copying the output into the file, which is what I'm trying to do. Do I have any options?

whenitrains
  • 468
  • 5
  • 21
  • 1
    you want to use `tee` – Ôrel Sep 21 '15 at 13:01
  • 4
    see [how-to-redirect-output-to-a-file-and-stdout](http://stackoverflow.com/questions/418896/how-to-redirect-output-to-a-file-and-stdout) – amdixon Sep 21 '15 at 13:03
  • Can be done from [within a script](http://stackoverflow.com/questions/3173131) as well. – DevSolar Sep 21 '15 at 13:04
  • This question is definitely not a duplicate of 418896. This question asks how to separate out stderr into its own file while simultaneously displaying all output on the screen, which is something that the linked "dupe" does not cover; it does not mention the &3 trick. A more related question is: http://stackoverflow.com/questions/2342826/how-to-pipe-stderr-and-not-stdout – PolyTekPatrick Oct 20 '15 at 05:05

1 Answers1

5

If you can have stdout and stderr into the file

command 2>&1 | tee -a log

Else you swap stdout and stderr using 3

{ command | tee stdout.log; } 3>&1 1>&2 2>&3 | tee stderr.log
gniourf_gniourf
  • 44,650
  • 9
  • 93
  • 104
Ôrel
  • 7,044
  • 3
  • 27
  • 46