Fix main CLI tools when stdout is not a tty and non ASCII chars are printed

http://stackoverflow.com/a/3828742/3223422