[comp.lang.perl] re

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

		I just found out that there is a C library routine - isatty
to know whether the STDOUT has been redirected to a file.
		So I guess I have to write a small C function to use it in my perl script.
		If you guys out there have any other ideas, I really would appreciate it.
		
		Thanks a lot.


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

tchrist@convex.COM (Tom Christiansen) (06/16/91)

From the keyboard of root@hotwheel.austin.ibm.com (/50000):
:>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
:
: I just found out that there is a C library routine - isatty
:to know whether the STDOUT has been redirected to a file.
: So I guess I have to write a small C function to use it in my perl script.
: If you guys out there have any other ideas, I really would appreciate it.

Just use the -t operator on the STDOUT handle.  Even if that weren't
available, you could just do a TIOCGETP ioctl on it instead.

--tom