Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: IPC::Open3, wperl issue

by thospel (Hermit)
on Jan 20, 2012 at 13:03 UTC ( [id://948956]=note: print w/replies, xml ) Need Help??


in reply to IPC::Open3, wperl issue

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: $!"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://948956]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-24 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found