Determine whether STDIN is a pipe?

H

h3xx

I have a program that uses Term::ANSIColor to print colored output,
but would like for it not to output the coloring escape sequences if
the output is being redirected to a program through a pipe.

In essence, it would act like grep's "--color=auto" flag.

Is there any way to test whether STDIN is going into a pipe?
 
H

h3xx

if (-t STDIN) {
    # It's a tty

} else {
    # It's a pipe
}

See: perldoc -f -x

sherm--

That works pretty well, but I think you mean "-t STDOUT". "-t STDIN"
seems to test for whether the INPUT is coming from a terminal. But
then again, I DID mix the two up in the subject line. Silly me.

Thanks a lot!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top