Why do colors not show up (control characters) when piping stdout/stderr on *nix systems?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite
1












Why do colors not show up (control characters) when piping stdout/stderr on *nix systems?



When I do:



foo | bar


if foo writes color encoded strings (with control chars) to stdout, they won't show up in bar - is there a way to get them to show up?







share|improve this question
















  • 2




    They do show up. You must be more specific, I suspect that you are talking about specific commands - for example ls detects if it writes to terminal and only then highlights the output. Test for example echo -e 'abce[31mdefe[0mghi' | cat.
    – jimmij
    Oct 14 '17 at 6:02











  • yeah when I am using a terminal, sometimes the colors still don't show up...?
    – Alexander Mills
    Oct 14 '17 at 6:24






  • 1




    Do you see red color with the command I gave or not?
    – jimmij
    Oct 14 '17 at 6:28










  • no I don't but I think that's a different issue
    – Alexander Mills
    Oct 14 '17 at 6:32






  • 1




    It turns out, from comments here and on Stack Overflow, that the real question was about a specific program that the questioner wrote whose message colourization library has a particular behaviour.
    – JdeBP
    Oct 14 '17 at 15:55














up vote
0
down vote

favorite
1












Why do colors not show up (control characters) when piping stdout/stderr on *nix systems?



When I do:



foo | bar


if foo writes color encoded strings (with control chars) to stdout, they won't show up in bar - is there a way to get them to show up?







share|improve this question
















  • 2




    They do show up. You must be more specific, I suspect that you are talking about specific commands - for example ls detects if it writes to terminal and only then highlights the output. Test for example echo -e 'abce[31mdefe[0mghi' | cat.
    – jimmij
    Oct 14 '17 at 6:02











  • yeah when I am using a terminal, sometimes the colors still don't show up...?
    – Alexander Mills
    Oct 14 '17 at 6:24






  • 1




    Do you see red color with the command I gave or not?
    – jimmij
    Oct 14 '17 at 6:28










  • no I don't but I think that's a different issue
    – Alexander Mills
    Oct 14 '17 at 6:32






  • 1




    It turns out, from comments here and on Stack Overflow, that the real question was about a specific program that the questioner wrote whose message colourization library has a particular behaviour.
    – JdeBP
    Oct 14 '17 at 15:55












up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





Why do colors not show up (control characters) when piping stdout/stderr on *nix systems?



When I do:



foo | bar


if foo writes color encoded strings (with control chars) to stdout, they won't show up in bar - is there a way to get them to show up?







share|improve this question












Why do colors not show up (control characters) when piping stdout/stderr on *nix systems?



When I do:



foo | bar


if foo writes color encoded strings (with control chars) to stdout, they won't show up in bar - is there a way to get them to show up?









share|improve this question











share|improve this question




share|improve this question










asked Oct 14 '17 at 5:50









Alexander Mills

1,9461029




1,9461029







  • 2




    They do show up. You must be more specific, I suspect that you are talking about specific commands - for example ls detects if it writes to terminal and only then highlights the output. Test for example echo -e 'abce[31mdefe[0mghi' | cat.
    – jimmij
    Oct 14 '17 at 6:02











  • yeah when I am using a terminal, sometimes the colors still don't show up...?
    – Alexander Mills
    Oct 14 '17 at 6:24






  • 1




    Do you see red color with the command I gave or not?
    – jimmij
    Oct 14 '17 at 6:28










  • no I don't but I think that's a different issue
    – Alexander Mills
    Oct 14 '17 at 6:32






  • 1




    It turns out, from comments here and on Stack Overflow, that the real question was about a specific program that the questioner wrote whose message colourization library has a particular behaviour.
    – JdeBP
    Oct 14 '17 at 15:55












  • 2




    They do show up. You must be more specific, I suspect that you are talking about specific commands - for example ls detects if it writes to terminal and only then highlights the output. Test for example echo -e 'abce[31mdefe[0mghi' | cat.
    – jimmij
    Oct 14 '17 at 6:02











  • yeah when I am using a terminal, sometimes the colors still don't show up...?
    – Alexander Mills
    Oct 14 '17 at 6:24






  • 1




    Do you see red color with the command I gave or not?
    – jimmij
    Oct 14 '17 at 6:28










  • no I don't but I think that's a different issue
    – Alexander Mills
    Oct 14 '17 at 6:32






  • 1




    It turns out, from comments here and on Stack Overflow, that the real question was about a specific program that the questioner wrote whose message colourization library has a particular behaviour.
    – JdeBP
    Oct 14 '17 at 15:55







2




2




They do show up. You must be more specific, I suspect that you are talking about specific commands - for example ls detects if it writes to terminal and only then highlights the output. Test for example echo -e 'abce[31mdefe[0mghi' | cat.
– jimmij
Oct 14 '17 at 6:02





They do show up. You must be more specific, I suspect that you are talking about specific commands - for example ls detects if it writes to terminal and only then highlights the output. Test for example echo -e 'abce[31mdefe[0mghi' | cat.
– jimmij
Oct 14 '17 at 6:02













yeah when I am using a terminal, sometimes the colors still don't show up...?
– Alexander Mills
Oct 14 '17 at 6:24




yeah when I am using a terminal, sometimes the colors still don't show up...?
– Alexander Mills
Oct 14 '17 at 6:24




1




1




Do you see red color with the command I gave or not?
– jimmij
Oct 14 '17 at 6:28




Do you see red color with the command I gave or not?
– jimmij
Oct 14 '17 at 6:28












no I don't but I think that's a different issue
– Alexander Mills
Oct 14 '17 at 6:32




no I don't but I think that's a different issue
– Alexander Mills
Oct 14 '17 at 6:32




1




1




It turns out, from comments here and on Stack Overflow, that the real question was about a specific program that the questioner wrote whose message colourization library has a particular behaviour.
– JdeBP
Oct 14 '17 at 15:55




It turns out, from comments here and on Stack Overflow, that the real question was about a specific program that the questioner wrote whose message colourization library has a particular behaviour.
– JdeBP
Oct 14 '17 at 15:55










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted











Why do colors not show up (control characters) when piping stdout/stderr on *nix systems?




As commented by jimij, they do show up.



However, some programs (probably most programs outputting ANSI escape codes) are detecting that their output is not a tty by using isatty(3) e.g. as isatty(STDOUT_FILENO); and that is a good feature, because dealing with escapes in pipelines when you don't want them is a pain.



Several programs document a way to force that, e.g. ls(1) has --color=always



So read the documentation of the relevant commands.






share|improve this answer




















  • yeah in my case, I control both foo and bar, and I want to figure out how to get the colors to show up
    – Alexander Mills
    Oct 14 '17 at 6:25










  • You read the documentation of both foo and bar.
    – Basile Starynkevitch
    Oct 14 '17 at 6:26










  • I think you misunderstood - I am authoring foo and bar
    – Alexander Mills
    Oct 14 '17 at 6:27






  • 2




    That should be a different question. Then show the code, perhaps as MCVE and ask it on StackOverflow.
    – Basile Starynkevitch
    Oct 14 '17 at 6:27











  • yeah maybe the package that I use to do the string styling will not do the styling if it's connected in a pipe? dunno
    – Alexander Mills
    Oct 14 '17 at 6:28










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f398060%2fwhy-do-colors-not-show-up-control-characters-when-piping-stdout-stderr-on-nix%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted











Why do colors not show up (control characters) when piping stdout/stderr on *nix systems?




As commented by jimij, they do show up.



However, some programs (probably most programs outputting ANSI escape codes) are detecting that their output is not a tty by using isatty(3) e.g. as isatty(STDOUT_FILENO); and that is a good feature, because dealing with escapes in pipelines when you don't want them is a pain.



Several programs document a way to force that, e.g. ls(1) has --color=always



So read the documentation of the relevant commands.






share|improve this answer




















  • yeah in my case, I control both foo and bar, and I want to figure out how to get the colors to show up
    – Alexander Mills
    Oct 14 '17 at 6:25










  • You read the documentation of both foo and bar.
    – Basile Starynkevitch
    Oct 14 '17 at 6:26










  • I think you misunderstood - I am authoring foo and bar
    – Alexander Mills
    Oct 14 '17 at 6:27






  • 2




    That should be a different question. Then show the code, perhaps as MCVE and ask it on StackOverflow.
    – Basile Starynkevitch
    Oct 14 '17 at 6:27











  • yeah maybe the package that I use to do the string styling will not do the styling if it's connected in a pipe? dunno
    – Alexander Mills
    Oct 14 '17 at 6:28














up vote
1
down vote



accepted











Why do colors not show up (control characters) when piping stdout/stderr on *nix systems?




As commented by jimij, they do show up.



However, some programs (probably most programs outputting ANSI escape codes) are detecting that their output is not a tty by using isatty(3) e.g. as isatty(STDOUT_FILENO); and that is a good feature, because dealing with escapes in pipelines when you don't want them is a pain.



Several programs document a way to force that, e.g. ls(1) has --color=always



So read the documentation of the relevant commands.






share|improve this answer




















  • yeah in my case, I control both foo and bar, and I want to figure out how to get the colors to show up
    – Alexander Mills
    Oct 14 '17 at 6:25










  • You read the documentation of both foo and bar.
    – Basile Starynkevitch
    Oct 14 '17 at 6:26










  • I think you misunderstood - I am authoring foo and bar
    – Alexander Mills
    Oct 14 '17 at 6:27






  • 2




    That should be a different question. Then show the code, perhaps as MCVE and ask it on StackOverflow.
    – Basile Starynkevitch
    Oct 14 '17 at 6:27











  • yeah maybe the package that I use to do the string styling will not do the styling if it's connected in a pipe? dunno
    – Alexander Mills
    Oct 14 '17 at 6:28












up vote
1
down vote



accepted







up vote
1
down vote



accepted







Why do colors not show up (control characters) when piping stdout/stderr on *nix systems?




As commented by jimij, they do show up.



However, some programs (probably most programs outputting ANSI escape codes) are detecting that their output is not a tty by using isatty(3) e.g. as isatty(STDOUT_FILENO); and that is a good feature, because dealing with escapes in pipelines when you don't want them is a pain.



Several programs document a way to force that, e.g. ls(1) has --color=always



So read the documentation of the relevant commands.






share|improve this answer













Why do colors not show up (control characters) when piping stdout/stderr on *nix systems?




As commented by jimij, they do show up.



However, some programs (probably most programs outputting ANSI escape codes) are detecting that their output is not a tty by using isatty(3) e.g. as isatty(STDOUT_FILENO); and that is a good feature, because dealing with escapes in pipelines when you don't want them is a pain.



Several programs document a way to force that, e.g. ls(1) has --color=always



So read the documentation of the relevant commands.







share|improve this answer












share|improve this answer



share|improve this answer










answered Oct 14 '17 at 6:21









Basile Starynkevitch

7,9231940




7,9231940











  • yeah in my case, I control both foo and bar, and I want to figure out how to get the colors to show up
    – Alexander Mills
    Oct 14 '17 at 6:25










  • You read the documentation of both foo and bar.
    – Basile Starynkevitch
    Oct 14 '17 at 6:26










  • I think you misunderstood - I am authoring foo and bar
    – Alexander Mills
    Oct 14 '17 at 6:27






  • 2




    That should be a different question. Then show the code, perhaps as MCVE and ask it on StackOverflow.
    – Basile Starynkevitch
    Oct 14 '17 at 6:27











  • yeah maybe the package that I use to do the string styling will not do the styling if it's connected in a pipe? dunno
    – Alexander Mills
    Oct 14 '17 at 6:28
















  • yeah in my case, I control both foo and bar, and I want to figure out how to get the colors to show up
    – Alexander Mills
    Oct 14 '17 at 6:25










  • You read the documentation of both foo and bar.
    – Basile Starynkevitch
    Oct 14 '17 at 6:26










  • I think you misunderstood - I am authoring foo and bar
    – Alexander Mills
    Oct 14 '17 at 6:27






  • 2




    That should be a different question. Then show the code, perhaps as MCVE and ask it on StackOverflow.
    – Basile Starynkevitch
    Oct 14 '17 at 6:27











  • yeah maybe the package that I use to do the string styling will not do the styling if it's connected in a pipe? dunno
    – Alexander Mills
    Oct 14 '17 at 6:28















yeah in my case, I control both foo and bar, and I want to figure out how to get the colors to show up
– Alexander Mills
Oct 14 '17 at 6:25




yeah in my case, I control both foo and bar, and I want to figure out how to get the colors to show up
– Alexander Mills
Oct 14 '17 at 6:25












You read the documentation of both foo and bar.
– Basile Starynkevitch
Oct 14 '17 at 6:26




You read the documentation of both foo and bar.
– Basile Starynkevitch
Oct 14 '17 at 6:26












I think you misunderstood - I am authoring foo and bar
– Alexander Mills
Oct 14 '17 at 6:27




I think you misunderstood - I am authoring foo and bar
– Alexander Mills
Oct 14 '17 at 6:27




2




2




That should be a different question. Then show the code, perhaps as MCVE and ask it on StackOverflow.
– Basile Starynkevitch
Oct 14 '17 at 6:27





That should be a different question. Then show the code, perhaps as MCVE and ask it on StackOverflow.
– Basile Starynkevitch
Oct 14 '17 at 6:27













yeah maybe the package that I use to do the string styling will not do the styling if it's connected in a pipe? dunno
– Alexander Mills
Oct 14 '17 at 6:28




yeah maybe the package that I use to do the string styling will not do the styling if it's connected in a pipe? dunno
– Alexander Mills
Oct 14 '17 at 6:28

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f398060%2fwhy-do-colors-not-show-up-control-characters-when-piping-stdout-stderr-on-nix%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay