Re: Single column when ls is redirected, how ?

From: Urs Thuermann (urs_at_isnogud.escape.de)
Date: 10/12/04

  • Next message: Jim Scott: "Re: EVIL AMERICAN GOVT (aka FBI) is full of SADISTS and PERVERTS"
    Date: 12 Oct 2004 13:03:26 +0200
    
    

    gopugopu@rediffmail.com (Gopu Bhaskar) writes:

    > _How_ is it that when one does an 'ls' on your console it displays the
    > output in multiple columns; and when you redirect the same to a file
    > it comes in a single column ?
    > Or to put it in a different way how does ls know where its stdout is ?

    ls can use isatty(3) to determine wether its stdout is a tty or not.
    isatty() usually tries some ioctls on the file descriptor which are
    valid only on a tty, e.g. TCGETS. On a tty, this ioctl will return 0,
    otherwise it will return -1 and errno is set to ENOTTY.

    urs


  • Next message: Jim Scott: "Re: EVIL AMERICAN GOVT (aka FBI) is full of SADISTS and PERVERTS"