[Perl] examples of IO::Pipe and IO:Handle

Offer Kaye oferk at oren.co.il
Mon Oct 28 01:45:55 PST 2002


----------------------------------
Offer Kaye
Analog and Circuit Design Engineer
Oren Semiconductor
oferk at oren.co.il
Tel: +972-4-9095555 ext. 1-309
----------------------------------

> -----Original Message-----
> From: perl-admin at perl.org.il [mailto:perl-admin at perl.org.il]On Behalf Of
> David Baird
> Sent: Monday, October 28, 2002 11:27 AM
> To: perl at perl.org.il
>
> I want to use the builtin function read() to capture the input from
> the child. I also cannot wait for the child process to terminate before
> acting on the output, which is why I cannot use the open() function with
> a pipe. The child process is also a Perl script, and I cannot change
> it, like to change $| to 1.

?
You don't have to wait for the child process to terminate to read the output
when using open with a pipe- as soon as the child start to output, the
parent can read it - at least, that's the way I understood it when you do an
implicit fork. See:
http://cs.haifa.ac.il/~shlomo/perl/lecture6/slide19.html

The code from that page:
#########################
die "Can't fork: $!" unless defined($pid = open(KID, "-|"));
if ($pid) {           # parent
	while (<KID>) {
		# do something
	}
	close KID;
} else {
	exec 'myprog', 'arg1', 'arg2' or die "can't exec myprog: $!";
}


Hope this helps :-)
Offer Kaye




More information about the Perl mailing list