• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

Catching errors in system call in Perl?

Is there anything wrong in this code? Especially on line 4 and 11.

          system("java -jar SOMEFILE.java");
          if ($? == -1) {
              #send email 
              sendEmail("$somename1@mywork.com", "somename2@mywork.com", "logging Failed", "failed to execute: $!\n");
          } elsif ($? & 127) {
              printf "child died with signal %d, %s coredump\n",
                ($? & 127),  ($? & 128) ? 'with' : 'without';
              my $signal = ($? & 127);
              my $woCoredump = ($? & 128) ? 'with' : 'without';
              #send email
              sendEmail("$somename1@mywork.com", "somename2@mywork.com", "Logging Failed", "child died with signal $signal, $woCodedump coredump\n");
          } else {
              # Don't do anything because it is a successful system call.
          }

Open in new window



and this is the sendEmail sub function

# Email Function
    #($to, $from, $subject, $message)
    sub sendEmail
      {
          my ($to, $from, $subject, $message) = @_;
          my $sendmail = '/usr/lib/sendmail';
          open(MAIL, "|$sendmail -oi -t");
          print MAIL "From: $from\n";
          print MAIL "To: $to\n";
          print MAIL "Subject: $subject\n\n";
          print MAIL "$message\n";
          close(MAIL);
      }

Open in new window

0
Tolgar
Asked:
Tolgar
  • 3
  • 2
2 Solutions
 
DonConsolioCommented:
> sendEmail("$somename1@mywork.com", "somename2@mywork.com", "logging Failed", "failed to execute: $!\n");

omit the "$" before somename1
sendEmail("somename1@mywork.com", "somename2@mywork.com", "logging Failed", "failed to execute: $!\n");
0
 
TolgarAuthor Commented:
Sounds good. So is this rest of my code is right?

I can't run and check it for now that is why I am asking.

Thanks,
0
 
ozoCommented:
Do you want to backquote the @ or do you want to interpolate an array named @mywork?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ozoCommented:
Or you may want to use q'' instead of qq""
0
 
TolgarAuthor Commented:
I don;t know what you mean by backquote but I want to send email to this email address: somename1@mywork.com

Then should I use \ before @ as the following?

somename1\@mywork.com

Thanks,
0
 
ozoCommented:

"somename1\@mywork.com"
or
'somename1@mywork.com'
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now