From mboxrd@z Thu Jan 1 00:00:00 1970 From: Phil Sutter Subject: [iproute PATCH 4/4] lib: Enable colored output only for TTYs Date: Wed, 15 Aug 2018 11:06:10 +0200 Message-ID: <20180815090610.16646-5-phil@nwl.cc> References: <20180815090610.16646-1-phil@nwl.cc> Cc: netdev@vger.kernel.org, Till Maas To: Stephen Hemminger Return-path: Received: from orbyte.nwl.cc ([151.80.46.58]:40046 "EHLO orbyte.nwl.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728576AbeHOL6C (ORCPT ); Wed, 15 Aug 2018 07:58:02 -0400 In-Reply-To: <20180815090610.16646-1-phil@nwl.cc> Sender: netdev-owner@vger.kernel.org List-ID: Add an additional prerequisite to check_enable_color() to make sure stdout actually points to an open TTY device. Otherwise calls like | ip -color a s >/tmp/foo will print color escape sequences into that file. Signed-off-by: Phil Sutter --- lib/color.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/color.c b/lib/color.c index edf96e5c6ecd7..500ba09682697 100644 --- a/lib/color.c +++ b/lib/color.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -79,7 +80,7 @@ void enable_color(void) int check_enable_color(int color, int json) { - if (color && !json) { + if (color && !json && isatty(fileno(stdout))) { enable_color(); return 0; } -- 2.18.0