Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by Anonymous Monk
on Mar 30, 2011 at 07:58 UTC ( [id://896336]=note: print w/replies, xml ) Need Help??


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

The return code from "system" is not unreliable, you're just interpreting it backwards. It's a really easy mistake to make - the shell interprets 0 as success and nonzero as failure. So a zero return code from a system call means it succeeded. The actual return code, if nonzero, is returned in the high-order byte of the return code, so if the shell returns 1 you'll get 256. That is usually not what you care about, you just want to know did it succeed or fail. So - change "or" to "and" and you're all set. It is clearer to say: if(system(...) != 0) { die(" ... "); }
  • Comment on Re: Best method to capture return code from system calls?

Log In?
Username:
Password:

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

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

    No recent polls found