http://www.perlmonks.org?node_id=991632

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 (Archbishop) on Sep 04, 2012 at 14:49 UTC

    Hello some_coder, and welcome to the Monastery!

    The 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