Redirecting bash stdout/stderr to two places?

前端 未结 3 424
误落风尘
误落风尘 2021-01-30 10:35

This one\'s been bugging me for a while now. Is it possible to redirect stdout and stderr to both the terminal output and to a program?

<
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-30 11:21

    I don't actually know whether TextMate can take a file to edit as its standard input, that seems a little bizarre. I suspect you would want to send the stdout/stderr to a file and edit it there, in which case you need:

    progname 2>&1 | tee tempfile ; textmate tempfile
    

    The 2>&1 redirects stderr (file handle 2) to go to the same place as stdout (file handle 1) so that both of them end up in a single stream. The tee command then writes that to tempfile as well as stdout.

    Then, once the process has finished, the editor is called up on the temporary file.

    If it can accept standard input for editing, use:

    progname 2>&1 | tee /dev/tty | textmate
    

提交回复
热议问题