How to write stdout to file with colors?

Since many programs will only output color sequences if their stdout is a terminal, a general solution to this problem requires tricking them into believing that the pipe they write to is a terminal. This is possible with the script command from bsdutils:

script -q -c "vagrant up" filename.txt

This will write the output from vagrant up to filename.txt (and the terminal). If echoing is not desirable,

script -q -c "vagrant up" filename > /dev/null

will write it only to the file.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)