How do I write stderr to a file while using “tee” with a pipe?

前端 未结 10 941
独厮守ぢ
独厮守ぢ 2020-11-22 08:01

I know how to use tee to write the output (STDOUT) of aaa.sh to bbb.out, while still displaying it in the terminal:

10条回答
  •  隐瞒了意图╮
    2020-11-22 08:49

    If using bash:

    # Redirect standard out and standard error separately
    % cmd >stdout-redirect 2>stderr-redirect
    
    # Redirect standard error and out together
    % cmd >stdout-redirect 2>&1
    
    # Merge standard error with standard out and pipe
    % cmd 2>&1 |cmd2
    

    Credit (not answering from the top of my head) goes here: http://www.cygwin.com/ml/cygwin/2003-06/msg00772.html

提交回复
热议问题