6 require Config; import Config;
9 if (!$Config{'d_fork'}) {
10 skip_all("fork required to pipe");
17 my $Perl = which_perl();
22 open(PIPE, "|-") || exec $Perl, '-pe', 'tr/YX/ko/';
24 printf PIPE "Xk %d - open |- || exec\n", curr_test();
26 printf PIPE "oY %d - again\n", curr_test();
31 # Technically this should be TODO. Someone try it if you happen to
32 # have a vmesa machine.
33 skip "Doesn't work here yet", 4 if $^O eq 'vmesa';
35 if (open(PIPE, "-|")) {
40 close PIPE; # avoid zombies
43 printf STDOUT "not ok %d - open -|\n", curr_test();
47 exec $Perl, '-le', "print q{not ok $tnum - again}";
50 # This has to be *outside* the fork
54 skip "fork required", 2 unless $Config{d_fork};
56 pipe(READER,WRITER) || die "Can't open pipe";
65 close READER; # avoid zombies
68 die "Couldn't fork" unless defined $pid;
70 printf WRITER "not ok %d - pipe & fork\n", curr_test;
73 open(STDOUT,">&WRITER") || die "Can't dup WRITER to STDOUT";
78 exec $Perl, '-le', "print q{not ok $tnum - with fh dup }";
81 # This has to be done *outside* the fork.
85 wait; # Collect from $pid
87 pipe(READER,WRITER) || die "Can't open pipe";
90 $SIG{'PIPE'} = 'broken_pipe';
93 $SIG{'PIPE'} = 'IGNORE'; # loop preventer
94 printf "ok %d - SIGPIPE\n", curr_test;
97 printf WRITER "not ok %d - SIGPIPE\n", curr_test;
103 # VMS doesn't like spawning subprocesses that are still connected to
104 # STDOUT. Someone should modify these tests to work with VMS.
107 skip "doesn't like spawning subprocesses that are still connected", 10
111 # Sfio doesn't report failure when closing a broken pipe
112 # that has pending output. Go figure. MachTen doesn't either,
113 # but won't write to broken pipes, so nothing's pending at close.
114 # BeOS will not write to broken pipes, either.
116 skip "Won't report failure on broken pipe", 1
117 if $Config{d_sfio} || $^O eq 'machten' || $^O eq 'beos' ||
120 local $SIG{PIPE} = 'IGNORE';
121 open NIL, qq{|$Perl -e "exit 0"} or die "open failed: $!";
123 if (print NIL 'foo') {
124 # If print was allowed we had better get an error on close
125 ok( !close NIL, 'close error on broken pipe' );
128 ok(close NIL, 'print failed on broken pipe');
133 skip "Don't work yet", 9 if $^O eq 'vmesa';
135 # check that errno gets forced to 0 if the piped program exited
137 open NIL, qq{|$Perl -e "exit 23";} or die "fork failed: $!";
139 ok(!close NIL, 'close failure on non-zero piped exit');
140 is($!, '', ' errno');
141 isnt($?, 0, ' status');
144 skip "Don't work yet", 6 if $^O eq 'mpeix';
146 # check that status for the correct process is collected
148 unless( $zombie = fork ) {
152 my $pipe = open *FH, "sleep 2;exit 13|" or die "Open: $!\n";
153 $SIG{ALRM} = sub { return };
155 is( close FH, '', 'close failure for... umm, something' );
156 is( $?, 13*256, ' status' );
157 is( $!, '', ' errno');
160 is( $?, 37*256, 'status correct after wait' );
161 is( $wait, $zombie, ' wait pid' );
162 is( $!, '', ' errno');
167 # Test new semantics for missing command in piped open
168 # 19990114 M-J. Dominus mjd@plover.com
170 ok( !open(P, "| "), 'missing command in piped open input' );
171 ok( !open(P, " |"), ' output');
174 # check that status is unaffected by implicit close
177 open NIL, qq{|$Perl -e "exit 23"} or die "fork failed: $!";
179 # NIL implicitly closed here
181 is($?, 42, 'status unaffected by implicit close');
184 # check that child is reaped if the piped program can't be executed
186 open NIL, '/no_such_process |';
191 local $SIG{ALRM} = sub { die; };
197 is($child, -1, 'child reaped if piped program cannot be executed');