Hi,
This is covered in the "Testing Whether a Program Is Running Interactively" in the Perl Cookbook (ISBN 0-596-00313-7).
sub I_am_interactive { return -t STDIN && -t STDOUT; }
Now, this isn't always full proof by any means. You could close either STDIN or STDOUT prior to checking. What I mean, is that if you use the example from the Perl Cookbook, then don't close either descriptor until after you test for interactivity. Be careful... especially if you are going to be using the code snippet in legacy code.
Jason L. Froebe
No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1
In reply to Re: How to tell whether script is invoked from command line or not
by jfroebe
in thread How to tell whether script is invoked from command line or not
by theguvnor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |