Demonstrate and work through some stdout and stderr redirection
In the shell it's necessary to watch the output from both pipes. Some tools are quite good with seperating stderr
from stdout
whereas others just pipe all error messages to stdout
.
NOTES:
- The difference between
>
and|
is that one redirects to a file and one to a process. Examples are here
TODO:
- find out if people use a 3rd FD for warnings and trace..
- piping just stderr to stdin
git fetch --dry-run 2>| tee
- prefixing name of pipe to each line....
# show what tty my stdin, stdout and stderr are connected to.
lsof +f g -ap $$ -d 0,1,2
It can be good to try different tools with a variety of paramaters to understand how the tool behaves regarding error logging.
# filter stdoout to show only error stream
cat ./no-file 1> /dev/null
# filter stderr to show only out stream
cat ./no-file 2> /dev/null
mkdir ./out
# generates stdout and stderr
./generate.sh
# filter off stdout
./generate.sh > ./out/stdout.txt
# filter off stderr
./generate.sh 2> ./out/stderr.txt
#filter both
./generate.sh > ./out/stdout2.txt 2> ./out/stderr2.txt
# prepend each stream with tag
./generate.sh 2> >(awk '{print "stderr:" $0}') > >(awk '{print "stdout:" $0}')
# merge stderr into stdout
./generate.sh &> ./out/stdout_combined.txt
# merge stderr into stdout
./generate.sh &> >(awk '{print "stdout:" $0}')