Re: Stumped: returning a read pipe from a function
- From: xhoster@xxxxxxxxx
- Date: 18 Aug 2007 23:20:37 GMT
kj <socyl@xxxxxxxxxxxxxxxxx> wrote:
Well, I'm getting close (I think). This is the best I've managed,
though it has at least a few problems:
use Socket;
use IO::Handle;
sub foo {
socketpair( my $child, my $parent, AF_UNIX,
SOCK_STREAM, PF_UNSPEC)
or die $!;
$_->autoflush( 1 ) for $child, $parent;
unless ( my $pid = fork ) {
die $! unless defined $pid;
close $child or die $!;
open STDOUT, '>&', $parent or die $!;
my $status = system "/some/command @_ 2>&1";
exit( $status ? 1 : 0 );
}
close $parent or die;
wait;
This is liable to deadlock. The parent won't start reading until the
child has exited. The child won't exit until the spawned process
has exited. The spawned process won't exit until it is done printing.
And, if what it is printing is more than one buffer full, then it can't
finish printing until the parent starts reading. Round and round you go.
This seems to work, but the system() call requires the shell, due
to the "2>&1" redirection. Also, it's a lot of machinery to do
something that is rather simple, conceptually at least.
I think you are over-estimating the conceptual simplicity of what you
are trying to do.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
.
- References:
- Prev by Date: Re: Stumped: returning a read pipe from a function
- Next by Date: how to call sub by value in variable
- Previous by thread: Re: Stumped: returning a read pipe from a function
- Next by thread: Re: Stumped: returning a read pipe from a function
- Index(es):
Relevant Pages
|