4 require Config; import Config;
6 # open2/3 supported on win32 (but not Borland due to CRT bugs)
7 && (($^O ne 'MSWin32' && $^O ne 'NetWare') || $Config{'cc'} =~ /^bcc/i))
13 $SIG{__WARN__} = sub { die @_ };
19 #require 'open3.pl'; use subs 'open3';
24 my ($n, $result, $info) = @_;
30 print "# $info\n" if $info;
35 if ($^O eq 'MSWin32' || $^O eq 'NetWare') {
46 my ($pid, $reaped_pid);
53 ok 1, $pid = open3 'WRITE', 'READ', 'ERROR', $perl, '-e', cmd_line(<<'EOF');
56 print STDERR "hi error\n";
58 ok 2, print WRITE "hi kid\n";
59 ok 3, <READ> =~ /^hi kid\r?\n$/;
60 ok 4, <ERROR> =~ /^hi error\r?\n$/;
61 ok 5, close(WRITE), $!;
62 ok 6, close(READ), $!;
63 ok 7, close(ERROR), $!;
64 $reaped_pid = waitpid $pid, 0;
65 ok 8, $reaped_pid == $pid, $reaped_pid;
68 # read and error together, both named
69 $pid = open3 'WRITE', 'READ', 'READ', $perl, '-e', cmd_line(<<'EOF');
72 print STDERR scalar <STDIN>;
74 print WRITE "ok 10\n";
76 print WRITE "ok 11\n";
80 # read and error together, error empty
81 $pid = open3 'WRITE', 'READ', '', $perl, '-e', cmd_line(<<'EOF');
84 print STDERR scalar <STDIN>;
86 print WRITE "ok 12\n";
88 print WRITE "ok 13\n";
93 ok 14, pipe PIPE_READ, PIPE_WRITE;
94 $pid = open3 '<&PIPE_READ', 'READ', '',
95 $perl, '-e', cmd_line('print scalar <STDIN>');
97 print PIPE_WRITE "ok 15\n";
103 $pid = open3 'WRITE', '>&STDOUT', 'ERROR',
104 $perl, '-e', cmd_line('print scalar <STDIN>');
105 print WRITE "ok 16\n";
108 # dup error: This particular case, duping stderr onto the existing
109 # stdout but putting stdout somewhere else, is a good case because it
111 $pid = open3 'WRITE', 'READ', '>&STDOUT',
112 $perl, '-e', cmd_line('print STDERR scalar <STDIN>');
113 print WRITE "ok 17\n";
116 # dup reader and error together, both named
117 $pid = open3 'WRITE', '>&STDOUT', '>&STDOUT', $perl, '-e', cmd_line(<<'EOF');
119 print STDOUT scalar <STDIN>;
120 print STDERR scalar <STDIN>;
122 print WRITE "ok 18\n";
123 print WRITE "ok 19\n";
126 # dup reader and error together, error empty
127 $pid = open3 'WRITE', '>&STDOUT', '', $perl, '-e', cmd_line(<<'EOF');
129 print STDOUT scalar <STDIN>;
130 print STDERR scalar <STDIN>;
132 print WRITE "ok 20\n";
133 print WRITE "ok 21\n";
136 # command line in single parameter variant of open3
137 # for understanding of Config{'sh'} test see exec description in camel book
138 my $cmd = 'print(scalar(<STDIN>))';
139 $cmd = $Config{'sh'} =~ /sh/ ? "'$cmd'" : cmd_line($cmd);
140 eval{$pid = open3 'WRITE', '>&STDOUT', 'ERROR', "$perl -e " . $cmd; };
146 print WRITE "ok 22\n";