For exmaple, the mysql command
mysql -e 'show databases'
+--------------------------+
| Database |
+--------------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------------+
But when you redirect to a file, the content is different, e.g.
mysql -e 'show databases' > /tmp/test.txt
cat /tmp/test.txt
Database
mysql
performance_schema
This is done by checking if STDOUT is connected to a TTY using the
isatty()call (in C, substitute the equivalent for your language of choice).