1#!./perl 2 3BEGIN { 4 unless(grep /blib/, @INC) { 5 chdir 't' if -d 't'; 6 @INC = '../lib'; 7 } 8} 9 10use Config; 11 12BEGIN { 13 if($ENV{PERL_CORE}) { 14 if ($Config{'extensions'} !~ /\bIO\b/) { 15 print "1..0 # Skip: IO extension not compiled\n"; 16 exit 0; 17 } 18 } 19} 20 21use IO::Handle; 22use IO::File; 23 24select(STDERR); $| = 1; 25select(STDOUT); $| = 1; 26 27print "1..6\n"; 28 29print "ok 1\n"; 30 31$dupout = IO::Handle->new->fdopen( \*STDOUT ,"w"); 32$duperr = IO::Handle->new->fdopen( \*STDERR ,"w"); 33 34$stdout = \*STDOUT; bless $stdout, "IO::File"; # "IO::Handle"; 35$stderr = \*STDERR; bless $stderr, "IO::Handle"; 36 37$stdout->open( "Io.dup","w") || die "Can't open stdout"; 38$stderr->fdopen($stdout,"w"); 39 40print $stdout "ok 2\n"; 41print $stderr "ok 3\n"; 42 43# Since some systems don't have echo, we use Perl. 44$echo = qq{$^X -le "print q(ok %d)"}; 45 46$cmd = sprintf $echo, 4; 47print `$cmd`; 48 49$cmd = sprintf "$echo 1>&2", 5; 50$cmd = sprintf $echo, 5 if $^O eq 'MacOS'; 51print `$cmd`; 52 53$stderr->close; 54$stdout->close; 55 56$stdout->fdopen($dupout,"w"); 57$stderr->fdopen($duperr,"w"); 58 59if ($^O eq 'MSWin32' || $^O eq 'NetWare' || $^O eq 'VMS') { print `type Io.dup` } 60elsif ($^O eq 'MacOS') { system 'Catenate Io.dup' } 61else { system 'cat Io.dup' } 62unlink 'Io.dup'; 63 64print STDOUT "ok 6\n"; 65