Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

start external program getting return code, stdout and stderr

by some_coder (Initiate)
on Sep 04, 2012 at 14:33 UTC ( #991632=perlquestion: print w/replies, xml ) Need Help??
some_coder has asked for the wisdom of the Perl Monks concerning the following question:

Hello, i know that i can start external progams using system or some kind of open(PROCESS,'<programname> |'). As far as i know both variants return either the return code of the called program (e.g. 0 for success, 1 for error) or the return values sent to stdout. I need an blocking call like system() and all three output values.

Let me explain what i want to accomplish. I want to call "apachefop" to generate some pdfs. apachefop prints massive warnings on stdout/stderr. Exceptions where displayed on stdout/stderr either. i want to log all the displayed errors and warnings only if the program did exit with an error. if it exits successfully i want to ignore the warnings.

i hope you can help me or point me to the right direction. Ah before i forget it, i am using Perl 5.8.8 in an Apache/mod_perl environment.

Replies are listed 'Best First'.
Re: start external program getting return code, stdout and stderr
by Athanasius (Chancellor) on Sep 04, 2012 at 14:49 UTC

    Hello some_coder, and welcome to the Monastery!

    The CPAN module Capture::Tiny will capture the output of STDOUT and STDERR (separately), as well as the return value of the called code. You can then use the return value to decide what (if anything) you want to do with the captured output.

    See the recent thread Problem logging STDOUT in perl.

    Hope that helps,

    Athanasius <°(((><contra mundum

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://991632]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2018-01-22 02:43 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (230 votes). Check out past polls.