talexb has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to build a mod_perl handler that will spawn and keep open a Ghostscript session that will produce a page image of from a specified document. The first step is to run Ghostscript and get it to produce a single page image from a specified document. And it's been a challenge.
I am re-using some proprietary Perl code that currently works fine when running from within another script by using IPC::Open3 and using pipes to communicate with Ghostscript. Running the same code under mod_perl causes problems: mod_perl complains that it can't find method FILENO in package Apache::RequestRec, and sure enough with a little googling we find that you can't use IPC::Open3 under mod_perl.
My first choice was to use IPC::Run, which seemed to work fine in my test programs from the command line, but failed when run under mod_perl; right now it seems I'm stuffing data into the input scalar ref, but it's not getting read, and I'm not sure why. (Yes, I do pump every once in a while.) There is a debug switch for this module, but it sends the output to STDOUT, something that's not on in mod_perl.
Off to IRC, good old #perl on freenode, where on Friday Caelum suggested using Expect instead. I made up a test program, it worked a treat, the code's much cleaner, so today I plugged it in, and wound up with a similar error to the one with IPC::Open3: mod_perl hates it when someone tries to close STDIN, which is what Expect is doing.
So today, after a bit of googling I came up with this link which seemed to be what I was looking for .. unfortunately there's no code for me to look at :(
I initialize as follows:
my ( $in, $out, $timer ); $logger->debug("Calling start .."); $$self{_h} = start ( \@cmd, \$in, \$out, $timer = timer ( 5 ) ) or $logger->logdie("start returned $?:$!"); $logger->debug("Back from start .."); $$self{_in} = \$in; $$self{_out} = \$out; $$self{_timer} = \$timer;
I am sending the data like this:
$$self{_in} .= $thisLine . "\n"; $$self{_h}->pump_nb;
Along the way I check out length($$self{_in}), but to my dismay it does not decrease -- there is no action.
So at this point, it seems that IPC::Run will do the trick, if I can only figure out how to unstick the input pipe going to Ghostscript, an thus produce some output, which would be useful. Any suggestions welcome.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trying to use IPC::Run under mod_perl
by perrin (Chancellor) on Dec 11, 2006 at 22:18 UTC | |
by robertlandrum (Initiate) on Dec 13, 2006 at 00:05 UTC | |
|
Re: Trying to use IPC::Run under mod_perl
by jbert (Priest) on Dec 11, 2006 at 21:23 UTC | |
by talexb (Chancellor) on Dec 11, 2006 at 21:30 UTC | |
by brig (Scribe) on Dec 12, 2006 at 00:56 UTC | |
by jbert (Priest) on Dec 12, 2006 at 09:04 UTC | |
|
Re: Trying to use IPC::Run under mod_perl
by shmem (Chancellor) on Dec 12, 2006 at 12:10 UTC | |
|
Re: Trying to use IPC::Run under mod_perl
by jbert (Priest) on Dec 12, 2006 at 11:11 UTC |