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.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds


In reply to Trying to use IPC::Run under mod_perl by talexb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.