Hello, I could use some help in getting IPC::Open3 to read from a network socket. The goal is to stream filesystem data to an external binary (zfs receive). I can read from the socket handle using angle brackets, and I can get open3 to work using a normal filehandle, but I can't combine the two and get open3 to read from the socket handle. Here is some distilled code:
#!/usr/bin/perl use warnings; use strict; use IO::Socket; use IPC::Open3; my $sock = new IO::Socket::INET ( LocalHost => '127.0.0.1', LocalPort => '1818', Proto => 'tcp', Listen => 1, ReuseAddr => 1, Timeout => 20 ); die "Could not create socket: $!\n" unless $sock; ## THIS WORKS (I can telnet to port 1818 from another terminal & see t +he text come across): #my $new_sock = $sock->accept() or die "No one came!"; #while ( <$new_sock> ) { print; } ## THIS WORKS (If I type "cat | ./<this_script>, I can type and see it + echo back): #my $pid = open3( "<&STDIN", ">&STDOUT", ">&STDERR", "/bin/cat" ); #waitpid( $pid, 0 ); # THIS DOES NOT WORK (using open3 to read from a network handle). my $new_sock = $sock->accept() or die "No one came!"; #my $pid = open3( $new_sock, ">&STDOUT", ">&STDERR", "/bin/cat" ); # c +an telnet to port but immediately disconnected my $pid = open3( $new_sock, $new_sock, ">&STDERR", "/bin/cat" ); # can + telnet to port but immediately disconnected waitpid( $pid, 0 ); close($sock);
I'm not particularly attached to using open3, I just want a way to connect my stream to to the external program. Am I missing something obvious or is this a limitation of open3? I've been avoiding IPC::Run so far as this will be copied to several computers & I'd prefer not to use a separate module. It's even fine if I can't redirect zfs receive's STDOUT or STDERR, as long as I can just connect STDIN and get the exit status. Thanks!

In reply to IPC::Open3 not connecting network socket handle by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.