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 # External program 'tr' assumed.
19 open(PIPE, "|-") || (exec 'tr', 'YX', 'ko');
31 if (open(PIPE, "-|")) {
36 close PIPE; # avoid zombies which disrupt test 12
39 # External program 'echo' assumed.
40 print STDOUT "not ok 3\n";
41 exec 'echo', 'not ok 4';
44 pipe(READER,WRITER) || die "Can't open pipe";
53 close READER; # avoid zombies which disrupt test 12
56 die "Couldn't fork" unless defined $pid;
58 print WRITER "not ok 5\n";
59 open(STDOUT,">&WRITER") || die "Can't dup WRITER to STDOUT";
61 # External program 'echo' assumed.
62 exec 'echo', 'not ok 6';
66 pipe(READER,WRITER) || die "Can't open pipe";
69 $SIG{'PIPE'} = 'broken_pipe';
72 $SIG{'PIPE'} = 'IGNORE'; # loop preventer
76 print WRITER "not ok 7\n";
81 # VMS doesn't like spawning subprocesses that are still connected to
82 # STDOUT. Someone should modify tests #9 to #12 to work with VMS.
92 if ($Config{d_sfio} || $^O eq 'machten' || $^O eq 'beos' || $^O eq 'posix-bc') {
93 # Sfio doesn't report failure when closing a broken pipe
94 # that has pending output. Go figure. MachTen doesn't either,
95 # but won't write to broken pipes, so nothing's pending at close.
96 # BeOS will not write to broken pipes, either.
101 local $SIG{PIPE} = 'IGNORE';
102 open NIL, '|true' or die "open failed: $!";
104 print NIL 'foo' or die "print failed: $!";
113 if ($^O eq 'vmesa') {
114 # These don't work, yet.
121 # check that errno gets forced to 0 if the piped program exited non-zero
122 open NIL, '|exit 23;' or die "fork failed: $!";
125 print "not ok 10\n# successful close\n";
128 print "not ok 10\n# errno $!\n";
131 print "not ok 10\n# status 0\n";
137 # check that status for the correct process is collected
138 wait; # Collect from $pid
139 my $zombie = fork or exit 37;
140 my $pipe = open *FH, "sleep 2;exit 13|" or die "Open: $!\n";
141 $SIG{ALRM} = sub { return };
143 my $close = close FH;
144 if ($? == 13*256 && ! length $close && ! $!) {
147 print "not ok 11\n# close $close\$?=$? \$!=", $!+0, ":$!\n";
150 if ($? == 37*256 && $wait == $zombie && ! $!) {
153 print "not ok 12\n# pid=$wait first=$pid pipe=$pipe zombie=$zombie me=$$ \$?=$? \$!=", $!+0, ":$!\n";