hi, monks ... looking for some wisdom here; my little brain can't figure out what I'm doing wrong.

basically, I am trying to use the open2 function from the IPC::Open2 module to: (a) send the contents of an array to the STDIN of "enscript", and (b) read the resulting STDOUT postscript code into an array.

Here is the code I'm using (lots of unrelated stuff snipped) ...

$|++; # put the args to enscript in an array ... my @enscript_args = ( "--no-header ", "--escapes ", "--font=AvantGarde-Book24 ", "--no-job-header ", "--quiet ", "--output=- " ); # here is where gnu enscript is on this system ... my $enscript = "/usr/bin/enscript"; # wrap the opening of enscript in an eval block, # so we can catch problems and die gracefully ... eval { open2 (*FROMENSCRIPT, *TOENSCRIPT, "$enscript @enscript_args"); }; if ( defined ($@) && $@ =~ /^open2/) { warn "$me: open2 failed: $!\n$@\n"; die }; print TOENSCRIPT (@burstpage); my @burstpage_ps = <FROMENSCRIPT>; close(TOENSCRIPT); close(FROMENSCRIPT);


the problem is that when I run this, an enscript process is spawned, but just hangs until I control-c the perl script. The "eval" statement provides me with no errors.

I assume that I'm running into a deadlock (I did rtfm, and my cookbook), and so I've seen the warnings that go with using open2; am I doing something stupid, or is there a better way of doing this? (I *really* don't want to use a temp file.)

Any help/advice would be greatly appreciated (even a "terse" solution from merlyn :-)

thanks!

In reply to need help with open2, please! by blueflashlight

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.