I was asked today about how to log the output of a command on Linux. It turns out that there are a number of ways of capturing output in *NIX environments. The well known method is to make the shell take care of it, for example, if you use bash you could:
echo "test" &>log.txt
$ script Script started output file is typescript
$ echo "foo" > /dev/tty
^D Script done, output file is typescript
After the shell exits, you should get a file called “typescript” which contains a plain text log of everything sent to the terminal. You can also have script record timing data so that the log can be played back (check out the manpage). Most scripting languages (and, of course, “expect”) can do something similar if you want to filter the output on the fly. One thing to be aware of with this method is that it will probably catch some control characters. If you look at your output in an editor these likely won't be rendered by their meaning. If you just “cat” the file from a terminal they may very well be displayed. You can always filter any unwanted characters with sed (or similar)}