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!!