in reply to Re: Re: pipes and return data
in thread pipes and return data

If you only have one batch of data to send to your child process, you can signal that you're done by just closing the write filehandle. The child process will see this as EOF in its STDIN, but will still be able to write to STDOUT just fine. Of course, once you've done this, you can't send any more data to the child process.

Here's a short example:

#!/usr/bin/perl -w # This is t6 use strict; use IPC::Open2; open2(\*READ,\*WRITE,'/tmp/t6b') or die "Error running sort: $!\n"; print WRITE join("\n",5,2,8,7,9,1,3,6,4,0),"\n"; close(WRITE); while (<READ>) { print "$0 read $_"; } #!/usr/bin/perl -w # This is t6b use strict; use vars qw(@a); while (<>) { push(@a,$_); } # OK, now we've gotten EOF. print sort @a;