The pipe basically takes the output of one thing and sends it to the input of other thing. Using tee lets you copy the flow of data to a file while sending it along. There's a caveat that the thing receiving the pipe actually takes input. Specifically from stdout.
Some basics:
0 stdin /dev/stdin
1 stdout /dev/stdout
2 stderr /dev/stderr
A practical demonstration:
FILE: bashtest.sh
Code:
#!/bin/bash
echo "some thing to stdout"
echo "some thing to stderr" >&2
echo "some thing else to stdout"
echo "some thing else to stderr" >&2
exit 0
$ bash bashtest.sh
some thing to stdout
some thing to stderr
some thing else to stdout
some thing else to stderr
$ bash bashtest.sh 2> tempSTDERR.txt
some thing to stdout
some thing else to stdout
$ cat tempSTDERR.txt
some thing to stderr
some thing else to stderr
$ bash bashtest.sh > tempSTDOUT.txt
some thing to stderr
some thing else to stderr
$ cat tempSTDOUT.txt
some thing to stdout
some thing else to stdout
$ bash bashtest.sh 2>&1 | > tempALL.txt
$ cat tempALL.txt
$ bash bashtest.sh 2>&1 | cat - > tempALL.txt
$ cat tempALL.txt
some thing to stdout
some thing to stderr
some thing else to stdout
some thing else to stderr
$ bash bashtest.sh 2>&1 | tee tempALL.txt
some thing to stdout
some thing to stderr
some thing else to stdout
some thing else to stderr
$ cat tempALL.txt
some thing to stdout
some thing to stderr
some thing else to stdout
some thing else to stderr
$ rm tempSTDERR.txt tempSTDOUT.txt tempALL.txt
$ bash bashtest.sh 2> tempSTDERR.txt > tempSTDOUT.txt
$ cat tempSTDERR.txt
some thing to stderr
some thing else to stderr
$ cat tempSTDOUT.txt
some thing to stdout
some thing else to stdout
$ cat tempALL.txt
cat: tempALL.txt: No such file or directory
Sometimes it's simpler to make a stupid test case like these to figure it out before modding/debugging the more complex monstrosity.