in reply to Re: EXIT code
in thread EXIT code

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: EXIT code
by Anonymous Monk on Jan 11, 2005 at 11:25 UTC
    Short, correct and useless answer: yes.

    Longer answer: any message written by the program is written to a certain file descriptor. Typically, error messages go to standard error, but if I got a nickle for every error message going to standard output, or half a cent for any non-error message going to standard error, I could buy Microsoft, IBM and Oracle, and still have cash to spare.

    So, you would have to find out where the programs error messages are going, and redirect that channel. For instance, in Posix like shells, messages on standard error (file descriptor 2) can be redirected to a file like this:

    program 2> errors_go_here
Re^3: EXIT code
by rev_1318 (Chaplain) on Jan 11, 2005 at 12:08 UTC
    You could, but it all depends on what you do with standard output; if you want to capture only the errors, and are not interested in standard output, this should work (in bash-like shells:
    ERRORTEXT=`perl -e 'die "Oops"' 2>&1 1>/dev/null` ERRORCODE=$?
    You can complicate things if you want both standard output and error captures, like:
    ERRORTEXT=`perl -e 'print "Hello\n";die "Oops"' 3>&1 1>&2 2>&3` ERRORCODE=$?
    Above sniplet prints Hello to standard error(!) and captures the result of 'die' in $ERRORTEXT. But then: why not extend your Perl program to handle what you want in the first place?

    Paul