This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
from the non-ANSI comment police (was: it won't compile on win32)
[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.
25$echo = qq{$^X -le "print q{ok %d}"};
26
27$cmd = sprintf $echo, 4;
28print `$cmd`;
29
30$cmd = sprintf "$echo 1>&2", 5;
31print `$cmd`;
32
33# KNOWN BUG system() does not honor STDOUT redirections on VMS.
34if( $^O eq 'VMS' ) {
35 print "not ok $_ # TODO system() not honoring STDOUT redirect on VMS\n"
36 for 6..7;
37}
38else {
39 system sprintf $echo, 6;
40 system sprintf "$echo 1>&2", 7;
41}
378cc40b 42
a687059c
LW
43close(STDOUT);
44close(STDERR);
378cc40b 45
ba553610
MS
46open(STDOUT,">&DUPOUT");
47open(STDERR,">&DUPERR");
378cc40b 48
cda41bc1 49if (($^O eq 'MSWin32') || ($^O eq 'NetWare') || ($^O eq 'VMS')) { print `type Io.dup` }
68dc0745 50else { system 'cat Io.dup' }
378cc40b
LW
51unlink 'Io.dup';
52
e4a4387c 53print STDOUT "ok 8\n";
9394203c 54