3 # $RCSfile: pipe.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:31 $
8 require Config; import Config;
9 unless ($Config{'d_fork'}) {
18 open(PIPE, "|-") || (exec 'tr', 'YX', 'ko');
23 if (open(PIPE, "-|")) {
28 close PIPE; # avoid zombies which disrupt test 12
31 print STDOUT "not ok 3\n";
32 exec 'echo', 'not ok 4';
35 pipe(READER,WRITER) || die "Can't open pipe";
44 close READER; # avoid zombies which disrupt test 12
47 die "Couldn't fork" unless defined $pid;
49 print WRITER "not ok 5\n";
50 open(STDOUT,">&WRITER") || die "Can't dup WRITER to STDOUT";
52 exec 'echo', 'not ok 6';
56 pipe(READER,WRITER) || die "Can't open pipe";
59 $SIG{'PIPE'} = 'broken_pipe';
65 print WRITER "not ok 7\n";
70 # VMS doesn't like spawning subprocesses that are still connected to
71 # STDOUT. Someone should modify tests #9 to #12 to work with VMS.
81 if ($Config{d_sfio} || $^O eq machten || $^O eq beos) {
82 # Sfio doesn't report failure when closing a broken pipe
83 # that has pending output. Go figure. MachTen doesn't either,
84 # but won't write to broken pipes, so nothing's pending at close.
85 # BeOS will not write to broken pipes, either.
89 local $SIG{PIPE} = 'IGNORE';
90 open NIL, '|true' or die "open failed: $!";
92 print NIL 'foo' or die "print failed: $!";
101 # check that errno gets forced to 0 if the piped program exited non-zero
102 open NIL, '|exit 23;' or die "fork failed: $!";
105 print "not ok 10\n# successful close\n";
108 print "not ok 10\n# errno $!\n";
111 print "not ok 10\n# status 0\n";
117 # check that status for the correct process is collected
118 my $zombie = fork or exit 37;
119 my $pipe = open *FH, "sleep 2;exit 13|" or die "Open: $!\n";
120 $SIG{ALRM} = sub { return };
122 my $close = close FH;
123 if ($? == 13*256 && ! length $close && ! $!) {
126 print "not ok 11\n# close $close\$?=$? \$!=", $!+0, ":$!\n";
129 if ($? == 37*256 && $wait == $zombie && ! $!) {
132 print "not ok 12\n# pid=$wait \$?=$? \$!=", $!+0, ":$!\n";