This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Unused variable
[perl5.git] / t / io / dup.t
CommitLineData
378cc40b
LW
1#!./perl
2
ba553610
MS
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
378cc40b 7
ba553610 8my $test = 1;
e4a4387c 9print "1..8\n";
378cc40b
LW
10print "ok 1\n";
11
ba553610
MS
12open(DUPOUT,">&STDOUT");
13open(DUPERR,">&STDERR");
378cc40b 14
ba553610 15open(STDOUT,">Io.dup") || die "Can't open stdout";
a687059c 16open(STDERR,">&STDOUT") || die "Can't open stderr";
378cc40b 17
a687059c
LW
18select(STDERR); $| = 1;
19select(STDOUT); $| = 1;
378cc40b 20
a687059c
LW
21print STDOUT "ok 2\n";
22print STDERR "ok 3\n";
ba553610
MS
23
24# Since some systems don't have echo, we use Perl.
dc459aad 25$echo = qq{$^X -le "print q(ok %d)"};
ba553610 26
dc459aad 27$cmd = sprintf $echo, 4;
ba553610
MS
28print `$cmd`;
29
dc459aad
JH
30$cmd = sprintf "$echo 1>&2", 5;
31$cmd = sprintf $echo, 5 if $^O eq 'MacOS'; # don't know if we can do this ...
ba553610
MS
32print `$cmd`;
33
34# KNOWN BUG system() does not honor STDOUT redirections on VMS.
35if( $^O eq 'VMS' ) {
36 print "not ok $_ # TODO system() not honoring STDOUT redirect on VMS\n"
37 for 6..7;
38}
39else {
40 system sprintf $echo, 6;
dc459aad
JH
41 if ($^O eq 'MacOS') {
42 system sprintf $echo, 7;
43 }
44 else {
45 system sprintf "$echo 1>&2", 7;
46 }
ba553610 47}
378cc40b 48
d1e4d418
A
49close(STDOUT) or die "Could not close: $!";
50close(STDERR) or die "Could not close: $!";
378cc40b 51
d1e4d418
A
52open(STDOUT,">&DUPOUT") or die "Could not open: $!";
53open(STDERR,">&DUPERR") or die "Could not open: $!";
378cc40b 54
cda41bc1 55if (($^O eq 'MSWin32') || ($^O eq 'NetWare') || ($^O eq 'VMS')) { print `type Io.dup` }
dc459aad
JH
56elsif ($^O eq 'MacOS') { system 'catenate Io.dup' }
57else { system 'cat Io.dup' }
378cc40b
LW
58unlink 'Io.dup';
59
e4a4387c 60print STDOUT "ok 8\n";
9394203c 61