open() and pipes
Dominic Mitchell
dom at happygiraffe.net
Tue Aug 1 12:49:40 BST 2006
On Tue, Aug 01, 2006 at 12:11:01PM +0100, David Cantrell wrote:
> I know that you can't do this ...
>
> open(FOO, '|program|')
>
> in perl to use an external program as a filter, and that the solution is
> to use IPC::Open2. But *why*? From taking a quick look at the procmail
> source*, it seems pretty easy to do. Yes, there's loads of caveats
> about buffering and so on, but if you need to do this, you need to do
> it, and the caveats apply just as much to IPC::Open2 as they would to
> doing it in the open() function.
>
> It just seems odd to me that this functionality is missing and that you
> need to use a module for it. Given that IPC::Open2 was bundled with the
> very first version of perl5, it seems odd that that functionality wasn't
> just rolled into open() at that time.
>
> Am I missing something obvious?
It's just far to easy to get into a situation where both ends of the
pipe ending up calling read() at the same time. At which point, you
have two deadlocked processes.
In a past life, I used the expect extension for TCL a lot to deal with
this sort of thing. Expect.pm is probably a good thing to look at in
the Perl world. It looks complicated. That's because it's doing
complicated stuff. :-)
-Dom
More information about the london.pm
mailing list