Prevent segmentation fault when output file is not TTY