Bash redirection: save stderr / stdout to different files and print them to the console

Here is a simple program.

class Redirection { public static void main (String args[]){ System.out.println("Hello World_Stdout"); System.err.println("Hello World_Stderr"); } } 

I want to see all the outputs on the console, but at the same time I want to store stdout and stderr in different files. I tried the following command, but to no avail.

 $java Redirection 3>&1 2>stderr 1>stdout 1>&3 2>&3 

STDERR & stdout files have a file size of 0.

So basically I want to do the "tee" command, but I also want to capture stderr as well.

+6
bash
source share
1 answer

Here is the answer:

./yourScript.sh > >(tee stdout.log) 2> >(tee stderr.log >&2)

If your script has STDOUT and STDERR descriptors, you get 2 stdout.log + stderr.log files and all the output (Err + Out) to the console.

+13
source share

All Articles