in reply to Re^3: IPC::Open3 not connecting network socket handle
in thread IPC::Open3 not connecting network socket handle

I don't think it is - it seems like my script is actually dying at the open3 step, while the child lives on (at least under 5.8.4). I'm dropped back to a shell prompt , even though my telnet session is still open in the other window and cat is still printing the text to my terminal. I removed the redundant close to no effect, it doesn't seem that the script had been getting that far.
#!/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; our $new_sock = $sock->accept() or die "No one came!"; my $pid = open3( "<&" . fileno($new_sock), ">&STDOUT", ">&STDERR", "/b +in/cat" ); waitpid( $pid, 0 );
Here is the result:
sh-3.2# ./test.pl open3: close(5) failed: Bad file number at ./test.pl line 21 sh-3.2# ps -ef | grep /bin/cat root 6124 6106 1 12:57:29 pts/3 0:00 grep /bin/cat root 6122 1 1 12:57:21 pts/3 0:00 /bin/cat sh-3.2# Blah blah this is text coming from my telnet session

Replies are listed 'Best First'.
Re^5: IPC::Open3 not connecting network socket handle
by ikegami (Patriarch) on Jul 24, 2009 at 17:16 UTC

    I don't think it is

    # If the write handle is a dup give it away entirely, close my copy # of it. xclose $dad_wtr if $dup_wtr;

    it seems like my script is actually dying at the open3 step

    Oops, yeah, I knew that. So it's an unrelated problem.

    Let's find out more details:

    $ perl -MCarp=verbose a.pl open3: close(4) failed: Bad file descriptor at /usr/share/perl/5.8/IPC +/Open3.pm line 70 IPC::Open3::xclose(4) called at /usr/share/perl/5.8/IPC/Open3. +pm line 218 IPC::Open3::_open3('open3', 'main', '<&4', '>&STDOUT', '>&STDE +RR', '/bin/cat') called at /usr/share/perl/5.8/IPC/Open3.pm line 229 IPC::Open3::open3('<&4', '>&STDOUT', '>&STDERR', '/bin/cat') c +alled at a.pl line 21

    Doh! It's calling close("4")!

    xclose $dad_wtr if $dup_wtr;

    should be

    if ($dup_wtr) { if (fh_is_fd($dad_wtr)) { xclose $dad_wtr; } else { xfdclose xfileno($dad_wtr); } }

    Defining xfdclose is left as a task to the reader.