Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Detecting interactive/non-interactive shell (Perl Cookbook)

by ybiC (Prior)
on Jul 03, 2005 at 20:38 UTC ( #472070=note: print w/replies, xml ) Need Help??


in reply to Detecting interactive/non-interactive shell

As per brother mifflin above, from the Perl Cookbook 1st ed, pp 518, 519...
  hth,
  ybiC

Use -t to test STDIN and STDOUT:

sub I_am_interactive { return -t STDIN && -t STDOUT; }

If you're on a POSIX system, test process groups:

sub I_am_interactive { local *TTY; # local file handle open(TTY, "/dev/tty") or die "can't open /dev/tty: $!"; my $tpgrp = tcgetpgrp(fileno(TTY)); my $pgrp = getpgrp(); close TTY; return ($tpgrp == $pgrp); }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://472070]
help
Chatterbox?
[Eily]: marto I clearly don't have the thread knowledge to understand the importance of that example

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2017-07-26 14:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (396 votes). Check out past polls.