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 | |
by ikegami (Patriarch) on Feb 10, 2012 at 09:29 UTC | |
by chessgui (Scribe) on Feb 10, 2012 at 10:13 UTC | |
by ikegami (Patriarch) on Feb 11, 2012 at 02:39 UTC |