<P>Extremely similar to open2(), <CODE>open3()</CODE> spawns the given $cmd and
connects RDRFH for reading, WTRFH for writing, and ERRFH for errors. If
ERRFH is false, or the same file descriptor as RDRFH, then STDOUT and
STDERR of the child are on the same filehandle. The WTRFH will have
autoflush turned on.</P>
<P>If WTRFH begins with <CODE><&</CODE>, then WTRFH will be closed in the parent, and
the child will read from it directly. If RDRFH or ERRFH begins with
<CODE>>&</CODE>, then the child will send output directly to that filehandle.
In both cases, there will be a <CODE>dup(2)</CODE> instead of a <A HREF="../../lib/Pod/perlfunc.html#item_pipe"><CODE>pipe(2)</CODE></A> made.</P>
<P>If either reader or writer is the null string, this will be replaced
by an autogenerated filehandle. If so, you must pass a valid lvalue
in the parameter slot so it can be overwritten in the caller, or
an exception will be raised.</P>
<P><CODE>open3()</CODE> returns the process ID of the child process. It doesn't return on
failure: it just raises an exception matching <CODE>/^open3:/</CODE>. However,
<A HREF="../../lib/Pod/perlfunc.html#item_exec"><CODE>exec</CODE></A> failures in the child are not detected. You'll have to
trap SIGPIPE yourself.</P>
<P><CODE>open2()</CODE> does not wait for and reap the child process after it exits.
Except for short programs where it's acceptable to let the operating system
take care of this, you need to do this yourself. This is normally as
simple as calling <CODE>waitpid $pid, 0</CODE> when you're done with the process.
Failing to do this can result in an accumulation of defunct or ``zombie''
processes. See <A HREF="../../lib/Pod/perlfunc.html#waitpid">waitpid in the perlfunc manpage</A> for more information.</P>
<P>If you try to read from the child's stdout writer and their stderr
writer, you'll have problems with blocking, which means you'll want
to use <A HREF="../../lib/Pod/perlfunc.html#item_select"><CODE>select()</CODE></A> or the IO::Select, which means you'd best use
<A HREF="../../lib/Pod/perlfunc.html#item_sysread"><CODE>sysread()</CODE></A> instead of <A HREF="../../lib/Pod/perlfunc.html#item_readline"><CODE>readline()</CODE></A> for normal stuff.</P>
<P>This is very dangerous, as you may block forever. It assumes it's
going to talk to something like <STRONG>bc</STRONG>, both writing to it and reading
from it. This is presumably safe because you ``know'' that commands
like <STRONG>bc</STRONG> will read a line at a time and output a line at a time.
Programs like <STRONG>sort</STRONG> that read their entire input stream first,
however, are quite apt to cause deadlock.</P>
<P>The big problem with this approach is that if you don't have control
over source code being run in the child process, you can't control
what it does with pipe buffering. Thus you can't just open a pipe to
<CODE>cat -v</CODE> and continually read and write a line from it.</P>
<P>
<HR>
<H1><A NAME="warning">WARNING</A></H1>
<P>The order of arguments differs from that of open2().</P>