How to determine whether output is a terminal?

Discussion in 'Perl Misc' started by Lars Haugseth, Nov 22, 2007.

  1. 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, Nov 22, 2007
    #1
    1. Advertisements

  2. perldoc -f -t


    John
     
    John W. Krahn, Nov 22, 2007
    #2
    1. Advertisements

  3. Ah, that simple. Thank you!
     
    Lars Haugseth, Nov 22, 2007
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.