in reply to Re^2: How to read from shell command and terminate it afterwards?
in thread How to read from shell command and terminate it afterwards?

You can use a socketpair to create a pipe out of sockets.

use Socket qw( AF_UNIX SOCK_STREAM PF_UNSPEC ); sub _pipe { socketpair($_[0], $_[1], AF_UNIX, SOCK_STREAM, PF_UNSPEC) or return undef; shutdown($_[0], 1); # No more writing for reader shutdown($_[1], 0); # No more reading for writer return 1; }

Use that as you would use pipe, then pass the writer end to open3.

use IPC::Open3 qw( open3 ); open(local *CHILD_STDIN, '<', 'nul:') or die $!; _pipe(\local *FROM_CHILD, \local *CHILD_STDOUT); my $pid = open3('<&CHILD_STDIN', '>&CHILD_STDOUT', '>&STDERR', $cmd); my $pipe = \*FROM_CHILD; ... waitpid($pid, 0);

Replies are listed 'Best First'.
Re^4: How to read from shell command and terminate it afterwards?
by chessgui (Scribe) on Feb 10, 2012 at 08:18 UTC
    I have not tested this as yet, but is this more simple? It looks more complicated.
      More simple or complicated than what?
        I can go ahead and use threads to deal with the STDOUT and STDERR of the child. Not more complicated than this.