[Vienna-pm] STDOUT-Umleitung
Leopold Toetsch
lt at toetsch.at
Fri Jan 21 03:33:57 PST 2005
Carl A. Schreiber wrote:
> Hallo,
>
> kann man eigentlich innerhalb eines Perl Programms herausfinden ob STDOUT
> 'aussen' (= beim Aufruf: ./bsp.pl >file.txt) in ein File umgeleitet wurde?
Ja. Mit POSIX::isatty
$ cat io.pl
#!/usr/bin/perl -w
use strict;
use IO::File;
use POSIX;
my $fh = IO::File->new(">-");
while (<>) {
print $fh $_;
}
print STDERR (isatty($fh) ? "Yes\n" : "No\n");
$ perl io.pl
asdf
^D
asdf
Yes
$ perl io.pl > 1
asdf
^D
No
leo
More information about the Vienna-pm
mailing list