How to determine whether output is a terminal?

L

Lars Haugseth

First, I hope the the question in the subject isn't the wrong one. What
I'm trying to do is to write a wrapper (in Perl) around the GNU 'ls'
command to format the output according to my liking. I know there are
several options in 'ls' to control output, but none that suits my needs.

By default, 'ls' adds colors when output is directly to a terminal.
However, if I capture the output of 'ls' through backticks, I don't get
colors. What I would like to do is for my Perl wrapper to determine
the nature of STDOUT, and add the "--color" option to 'ls' when appro-
priate (in accord with the default behavior of 'ls'.)

How would I go about doing this?
 
J

John W. Krahn

Lars said:
First, I hope the the question in the subject isn't the wrong one. What
I'm trying to do is to write a wrapper (in Perl) around the GNU 'ls'
command to format the output according to my liking. I know there are
several options in 'ls' to control output, but none that suits my needs.

By default, 'ls' adds colors when output is directly to a terminal.
However, if I capture the output of 'ls' through backticks, I don't get
colors. What I would like to do is for my Perl wrapper to determine
the nature of STDOUT, and add the "--color" option to 'ls' when appro-
priate (in accord with the default behavior of 'ls'.)

How would I go about doing this?

perldoc -f -t


John
 

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