3 IPC::Open2, open2 - open a process for both reading and writing
8 $pid = open2('rdr', 'wtr', 'some cmd and args');
10 $pid = open2('rdr', 'wtr', 'some', 'cmd', 'and', 'args');
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
18 open(HANDLE, "|cmd args");
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:/>.
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.
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.