I recently ran into the same problem and found this node. Before giving up I investigated further and decided that the standard answer (that this has to do with problems of wperl with STDERR) is incorrect or at least outdated. The problem is actually caused by open3 trying to set up a handle for STDIN. If you follow the code it turns out that in the end it does
open(IN, "<&GLOB")
where GLOB is a glob copy of STDIN. This fails under wperl (probably because STDIN is not sufficiently set up, I didn't trace that further). With that in mind I tried to set up a fake STDIN before doing the call and that seems to work as a workaround:
#!/usr/bin/perl -w
use strict;
use IPC::Open3;
open(STDIN, "<", "NUL") || die "open NUL: $!";
local (*IN,*OUT,*ERR);
my $pid = open3(\*IN, \*OUT, \*ERR, "wperl", q(-le), q(my $in = <STDIN
+>; print $in+3; print STDERR $in+5));
print IN "5\n";
close IN;
my $line = <OUT>;
print "Out=$line";
$line = <ERR>;
print "Err=$line";
And then:
wperl program > out 2>&1
type out
gives
Out=8
Err=10
Setting a global STDIN in the outer wperl is no great loss since it is not typically connected to anything anyways. If you want to be able to maybe use the STDIN of the outer wperl in case it is available I suppose you can replace the initial open by something like
{
open(my $dummy, "<&STDIN") || open(STDIN, "<", "NUL") || die "open
+ NUL: $!";
}