[comp.lang.perl] Redirection

root@hotwheel.austin.ibm.com (/50000) (06/12/91)

Hi guys,
	I have a question with respect to redirection.

	Is there a way to know whether the standard output has been redirectedinside a perl script.

eg : perl.script > perl.script.out 

here as you see the standard output is being redirected to perl.script.out


DISCLAIMER: My opinions are independent of IBM's position.

aks%anywhere@hub.ucsb.edu (Alan Stebbens) (06/13/91)

| Is there a way to know whether the standard output has been
| redirectedinside a perl script.
| 
| eg : perl.script > perl.script.out 

Just use the "-t" operator; e.g.:

  alias x perl -e \''printf STDERR "%sTTY\n",(-t STDOUT?"":"Not a ");'\'

  x
  TTY

  x > /dev/null
  Not a TTY

  x > /tmp/x
  Not a TTY

  x | cat
  Not a TTY

  x > /dev/console
  TTY