perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Quatravaux <>
Subject Re: Can't pipe to external programs
Date Wed, 07 Nov 2001 11:06:33 GMT
> Hey list,
> We're trying to turn some xml into a pdf using fop. A wrapper has been
> written for fop so that we can pass it xml on the stdin, and get the
> pdf from the stdout.
> We're using IPC::Open2 to set this up:

  I remember having lots of trouble with the implicit redirection
that mod_perl performs (IIRC, STD[IN|OUT|ERR] streams don't map to file
descriptors 0, 1 and 2 under mod_perl and this confuses IPC::Open[23]).

  I ended up recoding my very own fork() - pipe() - dup() - exec()
- exit() stuff, using POSIX::close(), POSIX::dup2() (that don't get
confused) and POSIX::SYS_exit() instead of exit() in the child process
(so that global variables representing e.g. a database connection
don't get destroyed, causing shutdown messages to get sent to the
remote server).

> use IPC::Open2;
> open2(*README, *WRITEME, "$progname");
> print WRITEME $thexml or warn "problem writing to $progname: $!\n";
> my $pdf = <README>;
> close(WRITEME);
> close(README);

  You should close WRITEME before attempting to read, or deadlock may
occur because either 1) WRITEME wasn't flushed from Perl's stdio buffers
and $progname didn't see any input yet, or 2) $progname doesn't see
end-of-file and thus expects more data.

<< Tout n'y est pas parfait, mais on y honore certainement les jardiniers >>

			Dominique Quatravaux <>

View raw message