open() and pipes
David Cantrell
david at cantrell.org.uk
Tue Aug 1 14:12:32 BST 2006
On Tue, Aug 01, 2006 at 12:49:40PM +0100, Dominic Mitchell wrote:
> 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.
Sure. You have that with IPC::Open2 as well. It's mentioned
prominently in the docs. Provided that it was as well-documented in
perlfunc I don't see what the problem would be.
In my particular application this is not an issue as the external
program *can not under any circumstances other than a fatal error* send
anything until I've finished writing to it.
> 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.
I'm not convinced that Expect is what I want. I want to do something
exactly the same as how procmail handles filters. Stuff goes in, gets
munged, and comes back out. I want all of what comes out, and I don't
need to do any pattern matching. Indeed, Expect doesn't even appear to
*have* a method for "gimme all the stuff what comes out".
> It looks complicated. That's because it's doing
> complicated stuff. :-)
Defnitly not what I need then. All I want to do is replace this ugly
hack ...
open(FOO), '|myprogram outputfile=foo.tmp');
print FOO 'munge this';
close(FOO);
# at this point some naughty chap replaces foo.tmp just to piss me off
open(FOORESULTS, 'foo.tmp');
my $munged = <FOORESULTS>;
close(FOORESULTS);
unlink 'foo.tmp';
with this ...
open(FOO, '|myprogram|');
print FOO, 'munge this';
my $munged = <FOO>;
close(FOO);
--
David Cantrell | Nth greatest programmer in the world
Feature: an incorrectly implemented bug
More information about the london.pm
mailing list