5 unshift @INC, '../lib';
6 require Config; import Config;
7 unless ($Config{'d_fork'}) {
8 print "1..0 # Skip: no fork\n";
16 # External program 'tr' assumed.
17 open(PIPE, "|-") || (exec 'tr', 'YX', 'ko');
25 print "ok $_ # skipped\n";
28 if (open(PIPE, "-|")) {
33 close PIPE; # avoid zombies which disrupt test 12
36 # External program 'echo' assumed.
37 print STDOUT "not ok 3\n";
38 exec 'echo', 'not ok 4';
41 pipe(READER,WRITER) || die "Can't open pipe";
50 close READER; # avoid zombies which disrupt test 12
53 die "Couldn't fork" unless defined $pid;
55 print WRITER "not ok 5\n";
56 open(STDOUT,">&WRITER") || die "Can't dup WRITER to STDOUT";
58 # External program 'echo' assumed.
59 exec 'echo', 'not ok 6';
62 wait; # Collect from $pid
64 pipe(READER,WRITER) || die "Can't open pipe";
67 $SIG{'PIPE'} = 'broken_pipe';
70 $SIG{'PIPE'} = 'IGNORE'; # loop preventer
74 print WRITER "not ok 7\n";
79 # VMS doesn't like spawning subprocesses that are still connected to
80 # STDOUT. Someone should modify tests #9 to #12 to work with VMS.
83 print "ok 9 # skipped\n";
84 print "ok 10 # skipped\n";
85 print "ok 11 # skipped\n";
86 print "ok 12 # skipped\n";
90 if ($Config{d_sfio} || $^O eq 'machten' || $^O eq 'beos' || $^O eq 'posix-bc') {
91 # Sfio doesn't report failure when closing a broken pipe
92 # that has pending output. Go figure. MachTen doesn't either,
93 # but won't write to broken pipes, so nothing's pending at close.
94 # BeOS will not write to broken pipes, either.
96 print "ok 9 # skipped\n";
99 local $SIG{PIPE} = 'IGNORE';
100 open NIL, '|true' or die "open failed: $!";
102 print NIL 'foo' or die "print failed: $!";
111 if ($^O eq 'vmesa') {
112 # These don't work, yet.
113 print "ok 10 # skipped\n";
114 print "ok 11 # skipped\n";
115 print "ok 12 # skipped\n";
119 # check that errno gets forced to 0 if the piped program exited non-zero
120 open NIL, '|exit 23;' or die "fork failed: $!";
123 print "not ok 10\n# successful close\n";
126 print "not ok 10\n# errno $!\n";
129 print "not ok 10\n# status 0\n";
135 # check that status for the correct process is collected
136 my $zombie = fork or exit 37;
137 my $pipe = open *FH, "sleep 2;exit 13|" or die "Open: $!\n";
138 $SIG{ALRM} = sub { return };
140 my $close = close FH;
141 if ($? == 13*256 && ! length $close && ! $!) {
144 print "not ok 11\n# close $close\$?=$? \$!=", $!+0, ":$!\n";
147 if ($? == 37*256 && $wait == $zombie && ! $!) {
150 print "not ok 12\n# pid=$wait first=$pid pipe=$pipe zombie=$zombie me=$$ \$?=$? \$!=", $!+0, ":$!\n";
153 # Test new semantics for missing command in piped open
154 # 19990114 M-J. Dominus mjd@plover.com
156 print (((open P, "| " ) ? "not " : ""), "ok 13\n");
157 print (((open P, " |" ) ? "not " : ""), "ok 14\n");
160 # check that status is unaffected by implicit close
163 open NIL, '|exit 23;' or die "fork failed: $!";
165 # NIL implicitly closed here
168 print "# status $?, expected 42\nnot ";