How to determine whether output is a terminal?

How to determine whether output is a terminal?

am 22.11.2007 05:28:47 von 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?

--
Lars Haugseth

"If anyone disagrees with anything I say, I am quite prepared not only to
retract it, but also to deny under oath that I ever said it." -Tom Lehrer

Re: How to determine whether output is a terminal?

am 22.11.2007 06:32:25 von krahnj

Lars Haugseth wrote:
>
> 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
--
use Perl;
program
fulfillment

Re: How to determine whether output is a terminal?

am 22.11.2007 07:02:46 von Lars Haugseth

* "John W. Krahn" wrote:
>
> Lars Haugseth wrote:
> >
> > 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

Ah, that simple. Thank you!

--
Lars Haugseth

"If anyone disagrees with anything I say, I am quite prepared not only to
retract it, but also to deny under oath that I ever said it." -Tom Lehrer