I am executing Java commands using backticks in Perl. I eval the command and look for errors in $@. But the error/warnings always go to the screen and never into $@.

I am trying to use some of the command line tools of the xml.apache.org project; Xerces-J, Xalan and FOP. The goal is to validate the XML, transform it, then create a PDF. I wish I could use AxKit, but I need to create PDFs and FOP is the only open source tool I could find to do this. One of the routines look like this;

sub validate_xml { my $file_r = shift; # use Xerces to validate xml eval { `java sax.SAXCount -v $$file_r`; }; if ($@) { print "$@\n"; &log_error($@); } }
It does the job, but I am going crazy trying to trap any errors or warnings. When there is an error it just prints it to the screen and it never gets into $@. I have read up on eval and system but I cannot figure out a way to get the results of the command into $@. I need to do error checking and logging for each of these routines. Is it a problem specific to Java commands, am I missing something in my eval? Or did I just drink too much coffee today? If anybody can help me I will toast to your collective honor and wisdom this weekend. mmmmmm ... toast

Get Strong Together!!


In reply to Trapping Java Errors by aardvark

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.