develooper Front page | perl.perl5.porters | Postings from October 2003

[perl #24204] Dupping STDERR for reading.

Thread Next
From:
perlbug-followup
Date:
October 14, 2003 17:04
Subject:
[perl #24204] Dupping STDERR for reading.
Message ID:
rt-24204-66024.5.54737049135795@rt.perl.org
# New Ticket Created by  camel@abigail.nl 
# Please include the string:  [perl #24204]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=24204 >



This is a bug report for perl from camel@abigail.nl,
generated with the help of perlbug 1.34 running under perl v5.8.1.


-----------------------------------------------------------------
[Please enter your report here]

A recent discussion on Perlmonks revealed that older versions
of Perl allowed you to dup STDERR for reads, but newer versions
don't. Opening STDERR for reading is a useful trick to be able
to read input from the keyboard if STDIN was redirected.

The following program shows the differences between the various
Perl versions:


    #!/usr/bin/perl

    use strict;
    use warnings;
    no warnings qw /syntax/;

    $| = 1;

    my $program = '$| = 1;
                   open STDERRIN, "<&STDERR" or die $!;
                   print "<$]> ";
                   my $line = <STDERRIN>;
                   chomp $line;
                   print "($]) Got: $line\n";';

    foreach my $version (qw /5.005 5.6.0 5.6.1 5.8.0 5.8.1 5.9.0/) {
        system "/opt/perl/$version/bin/perl -we '$program'";
        print "\n";
    }

    __END__
    <5.005> foo
    (5.005) Got: foo
     
    <5.006> bar
    (5.006) Got: bar
     
    <5.006001> Filehandle STDERRIN opened only for output at -e line 4.
    baz
    (5.006001) Got: baz
     
    <5.008> Filehandle STDERRIN opened only for output at -e line 4.
    Use of uninitialized value in scalar chomp at -e line 5.
    Use of uninitialized value in concatenation (.) or string at -e line 6.
    (5.008) Got:
     
    <5.008001> Filehandle STDERRIN opened only for output at -e line 4.
    Use of uninitialized value in scalar chomp at -e line 5.
    Use of uninitialized value in concatenation (.) or string at -e line 6.
    (5.008001) Got:
     
    <5.009> Filehandle STDERRIN opened only for output at -e line 4.
    Use of uninitialized value in scalar chomp at -e line 5.
    Use of uninitialized value in concatenation (.) or string at -e line 6.
    (5.009) Got:


Starting from 5.8.0, we can no longer read from the dupped STDERR.
5.6.1 warns that we can't, but still allows it.
         

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl v5.8.1:

Configured by abigail at Thu Sep 25 15:27:20 CEST 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.4.18-bf2.4, archname=i686-linux-64int-ld
    uname='linux alexandra 2.4.18-bf2.4 #1 son apr 14 09:53:28 cest 2002 i686 unknown '
    config_args='-des -Uversiononly -Dmydomain=.abigail.nl -Dcf_email=camel@abigail.nl -Dperladmin=camel@abigail.nl -Doptimize=-g -Dusemorebits -Dusedevel -Dusenm=false -Dprefix=/opt/perl -Dcc=gcc -Duse64bitint'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=undef uselongdouble=define
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-g',
    cppflags='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='3.0.4', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='long double', nvsize=12, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.2.5.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.2.5'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    Defined or
    No 'print (...) interpreted as function' warning

---
@INC for perl v5.8.1:
    /home/abigail/Perl
    /opt/perl/lib/5.8.1/i686-linux-64int-ld
    /opt/perl/lib/5.8.1
    /opt/perl/lib/site_perl/5.8.1/i686-linux-64int-ld
    /opt/perl/lib/site_perl/5.8.1
    /opt/perl/lib/site_perl/5.8.0/i686-linux-64int-ld
    /opt/perl/lib/site_perl/5.8.0
    /opt/perl/lib/site_perl
    .

---
Environment for perl v5.8.1:
    HOME=/home/abigail
    LANG=C
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/home/abigail/Lib:/usr/local/lib:/usr/lib:/lib:/usr/X11R6/lib
    LOGDIR (unset)
    PATH=/home/abigail/Bin:/opt/perl/bin:/usr/local/bin:/usr/local/X11/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/games:/usr/share/texmf/bin:/opt/Acrobat/bin:/opt/java/blackdown/j2sdk1.3.1/bin:/usr/local/games/bin
    PERL5LIB=/home/abigail/Perl
    PERLDIR=/opt/perl
    PERL_BADLANG (unset)
    SHELL=/bin/bash


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About