How to redirect stdout+stderr to one file while keeping streams separate?

后端 未结 5 1779
臣服心动
臣服心动 2020-12-28 19:39

Redirecting stdout+stderr such that both get written to a file while still outputting to stdout is simple enough:

cmd 2>&1 | tee output_file
         


        
5条回答
  •  旧时难觅i
    2020-12-28 20:11

    Victor Sergienko's comment is what worked for me, adding exec to the front of it makes this work for the entire script (instead of having to put it after individual commands)

    exec 2> >(tee -a output_file >&2) 1> >(tee -a output_file)

提交回复
热议问题