Results 1 to 6 of 6
I want to include some error checking in my code for the system command
system("ls -z"); didn't not print any error in the terminal.
system("ls") gave an exit status of ...
- 04-12-2007 #1Just Joined!
- Join Date
- Apr 2007
- Posts
- 5
Exit status of system command??
I want to include some error checking in my code for the system command
system("ls -z"); didn't not print any error in the terminal.
system("ls") gave an exit status of 1 in my system,does this value vary on different systems??
please help.
- 04-12-2007 #2
i believe ANY system command exist with status of 0 if it fails, and any other number if it succeeds. So if you wanted an operator to check it failed, check the status is 0, if it is, it failed, otherwise it succeeded.
"I am not an alcoholic, alcoholics go to meetings"
Registered Linux user = #372327
- 04-12-2007 #3
system() returns -1 on error and returns the status code of the shell command otherwise. It is standard practice to exit anything with a status code of 0 meaning success. Anything else is an error.
- 04-13-2007 #4Just Joined!
- Join Date
- Dec 2003
- Posts
- 41
As was pointed out above, a return of zero means success and any non zero means failure. You can check this by running some commads (then some incorrent commands) and check the return code after each command by using: echo $?
- 04-13-2007 #5
As far as completely exiting a command or a main function, this is standard practice. However a function can really return any value, int pointer char whatever. The system() just so happens to work like I just described, which is pretty logical behavior.
- 04-16-2007 #6Just Joined!
- Join Date
- Apr 2007
- Posts
- 5
i tried the below and it worked.
system(cmd) ==0 || die(msg)
Thanks.


Reply With Quote