GraemeByers has asked for the wisdom of the Perl Monks concerning the following question:

A Perl newbie asks : 1. If an application program invoked from Perl abends, how can I detect in Perl the type of abend (zero-divide etc) or even that it has abended ? 2. I want to return an integer from my application program to Perl to indicate un/success - how can I pick up the value in Perl ? Thankyou.

Replies are listed 'Best First'.
Re: Values returned to Perl
by Zaxo (Archbishop) on Jun 08, 2004 at 18:26 UTC

    For properties of $?, see perlvar.

    You can also work directly with the value returned by system, or array context wait/waitpid, if you have forked the process.

    After Compline,
    Zaxo

Re: Values returned to Perl
by hsinclai (Deacon) on Jun 08, 2004 at 20:34 UTC
    Sure it's easy enough to collect the return code (if any) from another failing program, after it was invoked from Perl..

    What if an external program terminates with a single error code -- but for different causes, while additionally printing errors to standard output?
    You didn't mention your platform, but at least on Unix and for some Windows programs, you could invoke your program from Perl along with some extra flags, redirecting any errors into a disk file, which your Perl script can read and analyze..
    /my/prog 2> /private/debug-output.txt
    To specifically answer your question 2: As others had said $? is what you need - but first find out what error codes your external program can return - that way you'll know what to match for in your Perl program.

    At least there's one idea - but how you implement depends on a few variables - your program, what else it does, lots of things... if you post some code we'll get a better idea of your final intent..

    If all you're looking to do is find out when your program died, use a wrapper script that tries to restart it and notify you ..
Re: Values returned to Perl
by BUU (Prior) on Jun 08, 2004 at 18:20 UTC
    $?