Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

error messages

by saldoman (Initiate)
on May 13, 2005 at 13:15 UTC ( [id://456718]=perlquestion: print w/replies, xml ) Need Help??

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

I want to send an error message to a file from a system call. system("some function here") || warn "some failure here: $?";

Replies are listed 'Best First'.
Re: error messages
by thundergnat (Deacon) on May 13, 2005 at 13:25 UTC

    Check out the perl faqs which specifically address this situation.

    perldoc -f system

    It lists how to inspect the return value from a system call.

    if ($? == -1) { print "failed to execute: $!\n"; } elsif ($? & 127) { printf "child died with signal %d, %s coredump\n" ($? & 127), ($? & 128) ? 'with' : 'without'; } else { printf "child exited with value %d\n", $? >> 8; }

    Modify to suit.

      Excellent answer. Just to be complete, this is the short version:
      system("/my/shell/prog") && die "System failed: $!"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://456718]
Approved by rev_1318
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-23 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found