]> granicus.if.org Git - sysstat/commitdiff
Disable color output if stdout is not a terminal
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 13 Sep 2015 08:57:51 +0000 (10:57 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 13 Sep 2015 08:57:51 +0000 (10:57 +0200)
Don't color output if it's redirected to a pipe or a file.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
common.c

index e6af880ae295f9584b7ff749695bf2b9644d02e2..c3034e17341a0f0ffe7edc66d59aa0ac52bdeb3d 100644 (file)
--- a/common.c
+++ b/common.c
@@ -936,8 +936,11 @@ char *get_pretty_name_from_persistent(char *persistent)
 void init_colors(void)
 {
        /* Read environment variable value */
-       if (getenv(ENV_COLORS) == NULL) {
-               /* Environment variable not set: Unset color strings */
+       if (!getenv(ENV_COLORS) || !isatty(STDOUT_FILENO)) {
+               /*
+                * Environment variable is not set or stdout is not a terminal:
+                * Unset color strings.
+                */
                strcpy(sc_percent_high, "");
                strcpy(sc_percent_low, "");
                strcpy(sc_zero_int_stat, "");