1use warnings;
2use strict;
3
4use Config;
5BEGIN {
6	# open2/3 supported on win32, but not Borland due to CRT bugs
7	if(!$Config{d_fork} &&
8			(($^O ne 'MSWin32' && $^O ne 'NetWare') ||
9			 $Config{cc} =~ /^bcc/i)) {
10		require Test::More;
11		Test::More->import(skip_all =>
12			"open2/3 not available with MSWin32+Netware+cc=bcc");
13	}
14}
15
16BEGIN {
17	# make warnings fatal
18	$SIG{__WARN__} = sub { die @_ };
19}
20
21use IO::Handle;
22use Test::More tests => 8;
23
24require_ok "open2.pl";
25
26my $perl = $^X;
27
28sub cmd_line {
29	if ($^O eq 'MSWin32' || $^O eq 'NetWare') {
30		return qq/"$_[0]"/;
31	}
32	else {
33		return $_[0];
34	}
35}
36
37my ($pid, $reaped_pid);
38STDOUT->autoflush;
39STDERR->autoflush;
40
41$pid = &open2('READ', 'WRITE', $^X, '-e', cmd_line('print scalar <STDIN>'));
42ok $pid;
43ok print(WRITE "hi kid\n");
44like scalar(<READ>), qr/\Ahi kid\r?\n\z/;
45ok close(WRITE);
46ok close(READ);
47$reaped_pid = waitpid $pid, 0;
48is $reaped_pid, $pid;
49is $?, 0;
50
511;
52