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); }


Comment on Re: Detecting interactive/non-interactive shell (Perl Cookbook)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://472070]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (22)
As of 2015-07-07 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (90 votes), past polls