Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

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

by ybiC (Prior)
on Jul 03, 2005 at 20:38 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://472070]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-29 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found