1

I hope to record the result of stderr & stdout to different files, while watching both outputs from the terminal.

So I use tee, and found a solution in this page.

But the sad thing is, it can't work when put into a makefile:

all:
    @command > >(tee stdout.log) 2> >(tee stderr.log >&2)

It seems that make will use sh -c to execute this line, which doesn't understand well about the syntax.

Can we have another solution for this?

Community
  • 1
  • 1
sleepsort
  • 1,301
  • 13
  • 28
  • `tee` works; it's the process substitution that the shell used by `make` doesn't understand. – chepner May 09 '13 at 15:02
  • 1
    a workaround is to set the variable `SHELL` in make to `/bin/bash` using `make SHELL=/bin/bash`, or putting `SHELL:=/bin/bash` at the start of the `Makefile`. – Petesh May 09 '13 at 15:08
  • Thanks @Petesh, can you post the answer so I can mark this as solved? – sleepsort May 09 '13 at 15:11

2 Answers2

3

In order to use this syntax in your Makefile you need to change the shell that make uses for running commands by setting the SHELL variable.

By invoking make using: make SHELL=/bin/bash, or putting SHELL:=/bin/bash at the start of the Makefile it should accomplish this.

Petesh
  • 87,225
  • 3
  • 99
  • 116
0

A brute-force way would be to not tee in the makefile but instead tail -f one of the files in the background:

$ tail -f stderr.log & tail -f stdout.log
[... ^C]
$ kill $!
jthill
  • 48,781
  • 4
  • 72
  • 120