Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: STDOUT redirects and IPC::Open3

by ikegami (Pope)
on Oct 18, 2011 at 06:31 UTC ( #932075=note: print w/ replies, xml ) Need Help??


in reply to STDOUT redirects and IPC::Open3

The child cannot possibly write to the variable in the parent process. This child has no access to the parent's memory space even if it had any understanding of Perl variables. That's what open3 normally creates pipes for you.


Comment on Re: STDOUT redirects and IPC::Open3
Re^2: STDOUT redirects and IPC::Open3
by kennethk (Monsignor) on Oct 18, 2011 at 14:47 UTC
    I don't follow how this is relevant to the question at hand. open3 sets up pipes to the child process, and those pipes are read in the test sub. test in turn prints to the parent STDOUT, which has been redirected to a scalar. Why would a redirect in the parent have any impact on the child's I/O?

    Update: Mucking about, I discovered this seems to be associated with localizing the file handle.

    #!/usr/bin/perl -w use strict; use IPC::Open3; use Symbol 'gensym'; my @queue = ("Line 1\nThis is the first line\n", "Line 2\nThis is the second line\n", "Line 3\nThis is the third line\n", ); for my $line (@queue) { local *STDOUT; open LOG, '>', \my $stdout or die "Can't catch LOG: $!"; my $pid = open3(my $wtr, my $rdr, undef, 'cat', '-v'); print $wtr $line; close $wtr; my $content=do{local $/;<$rdr>}; waitpid( $pid, 0 ); close LOG; }
    leaks the output, but commenting line 13 causes the capture to operate properly.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-07-29 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls