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

If only this would work on Windows. Life would be much simpler.
  • Comment on Re^2: How to read from shell command and terminate it afterwards?

Replies are listed 'Best First'.
Re^3: How to read from shell command and terminate it afterwards?
by ikegami (Patriarch) on Feb 10, 2012 at 07:53 UTC

    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);
      I have not tested this as yet, but is this more simple? It looks more complicated.
        More simple or complicated than what?