almel
almel

Reputation: 7968

How redirect program's stdout and stderr to one file, and the same stderr to another file?

I want to have a log file merged.log which stores the full program output (stdout and stderr) so I can see error logs alongside non-error logs, but also have a file error.log only for error lines so I can quickly view problems in the program. I have tried using tee but I can't figure out how to perform this particular type of redirection.

For example, if I have the following javascript program

// outputter.js
console.log('this is stdout');
console.error('this is stderr');

then the two log files should be

# merged.log
this is stdout
this is stderr

and

# error.log
this is stderr

Upvotes: 2

Views: 304

Answers (1)

roger
roger

Reputation: 121

In BASH this works for me:

((./a.out 2>&1 1>&3 | tee error.log) 3>&1 1>&2) > merged.log 2>&1

There is a good explanation at this page.

Upvotes: 2

Related Questions