19f0369cfd348efb13e7eb0931f4285ba8aa04e8
[p5sagit/p5-mst-13.2.git] / pod / modpods / Open2.pod
1 =head1 NAME
2
3 IPC::Open2, open2 - open a process for both reading and writing
4
5 =head1 SYNOPSIS
6
7     use IPC::Open2;
8     $pid = open2('rdr', 'wtr', 'some cmd and args');
9       # or
10     $pid = open2('rdr', 'wtr', 'some', 'cmd', 'and', 'args');
11
12 =head1 DESCRIPTION
13
14 The open2() function spawns the given $cmd and connects $rdr for
15 reading and $wtr for writing.  It's what you think should work 
16 when you try
17
18     open(HANDLE, "|cmd args");
19
20 open2() returns the process ID of the child process.  It doesn't return on
21 failure: it just raises an exception matching C</^open2:/>.
22
23 =head1 WARNING 
24
25 It will not create these file handles for you.  You have to do this yourself.
26 So don't pass it empty variables expecting them to get filled in for you.
27
28 Additionally, this is very dangerous as you may block forever.
29 It assumes it's going to talk to something like B<bc>, both writing to
30 it and reading from it.  This is presumably safe because you "know"
31 that commands like B<bc> will read a line at a time and output a line at
32 a time.  Programs like B<sort> that read their entire input stream first,
33 however, are quite apt to cause deadlock.  See L<open3> for an alternative.