Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Best method to capture return code from system calls?

by dave_the_m (Parson)
on Aug 24, 2005 at 14:52 UTC ( #486216=note: print w/ replies, xml ) Need Help??


in reply to Best method to capture return code from system calls?

Note that system() returns a false value on success, so system(...) or ... is the wrong idiom. Your code was succeeding, then printing out a suprious error.

perlfunc demonstrates the most comprehensive checking code:

system(...); 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; }
Note some further subtleties: since you are giving the command as a single string, it is executed by a shell, and you are actually checking the exit status of the shell rather than the command the shell is executing (although the shell normally returns the code of the last command it executed.)

But as has been pointed out, use File::Copy.

Dave.


Comment on Re: Best method to capture return code from system calls?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://486216]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-07-28 22:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (210 votes), past polls