Hi all,
I've been looking for the way to send stdout and stderr to different files. Well, actually I really knew how to make it, but I wanted to be sure.
I've found an instruction very interesting which I'm not able to understand:
Quote:
((/path/to/oraMon.pl 2>&1 1>&3 | tee /tmp/errors.log) 3>&1 1>&2 | tee /tmp/output.log) > /tmp/final.log 2>&1
taken from
this site. It says it sends stdout to output.log, stderr to errors.log, and both to final.log.
I know 3 is another file descriptor, but which file does it refers? How does it work?
I think I understand:
- oraMon.pl 2>&1 1>&3: stderr is redirected to stdout and stdout is redirected to 3
- tee /tmp/errors.log 3>&1 1>&2: takes the standards output previous command, and saves it to a file. However, I don't understand why 3 is redirected to stdout, and sdout to stderr.
I still have another question. The difference between this two instructions:
Quote:
./command > mylog.log 2>&1
./command 2>&1 > mylog.log
I know first one redirects both stdout and stderr to mylog.log. The second one, I read the stderr is redirected to stdout, and stdout is redirected to a file. So I thought both should be the same, but I also read only stdout is saved to a file in the second instruction. Why?
Sorry for this large question, but I'd like to understand redirection and file descriptors.
Thanks a lot.
Albert.