![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help on function call | kamel.seg | Shell Programming and Scripting | 3 | 01-08-2008 04:16 AM |
| call function | Jamil Qadir | Shell Programming and Scripting | 4 | 03-20-2007 02:07 AM |
| Help with a function call | Stevhp | High Level Programming | 6 | 03-04-2007 11:44 PM |
| function call | forever_49ers | Shell Programming and Scripting | 3 | 09-13-2006 03:26 PM |
| UNIX Sytem 5, release 3 | samklyle | UNIX for Dummies Questions & Answers | 5 | 07-14-2001 01:08 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
i want to know the return value of calling system function in the sco unix 5.0.5.what is the meaning of the return value?
............ int ret; char cmd[128]; strcpy(cmd,"compress -F -c file >file.Z"); ret = system(cmd); ............. i want to know how to judge whether the file's compress is success due to the ret value; please help me! thanks |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
"system" on failure normally returns "-1" i.e if either fork, exec or waitpid which are internally called "System" fail.
Rather than checking for the return value, you can check the value set in the system defined global variable "errno" after executing "system". the value of errno can let you know the staus after execution of "system" Be sure to include the file "errno.h" . But even "errno" is not full proof. I think others would certainly have better ideas.. |
|
#3
|
|||
|
|||
|
thanks for your advice,but it is not right through judging the errno values,
example: #include <stdio.h> #include <errno.h> main() { int ret; char cmd[128]; strcpy(cmd,"compress /tmp/lll"); ret = system(cmd); printf("after system errno[%d], ret[%d]\n", errno, ret); exit(0); } if the fileˇ°/tmp/lllˇ± doesnot exist,execute this program,screen will output: compress: could not read /tmp/lll: No such file or directory (error 2) after system errno[0], ret[256] errno only represents the result of calling system function,not the result of the command (compress). #include <stdio.h> #include <errno.h> main() { int ret; char cmd[128]; strcpy(cmd,"compress /tmp/lll"); ret = system(cmd); /* add this sentence"/ ret >>= 8 printf("after system errno[%d], ret[%d]\n", errno, ret); if ( ret == 0 ) printf("compress success\n"); else printf("compress failure\n"); exit(0); } is it right to judge whether the file compress is success though the ret >>= 8; |
|
#4
|
|||
|
|||
|
well, it makes sense to see the value of of both "ret" and "errno". But how did u get this magic number of 8 ??
"ret >>=8" Its better to check that the value of ret is 0. Even values greater than zero denote an error. |
|
#5
|
|||
|
|||
|
The status of a child process may be interpreted using the following macros, which are defined in <sys/wait.h> :
WIFEXITED(status) WEXITSTATUS(status) and others. Here the status is the integer value returned by the system function. Example : ret = WEXITSTATUS ( system ( "command > /dev/null " ) ) ; a value 0 always means success.
__________________
Regards, Satya Prakash Prasad |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|