The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-16-2002
hit hit is offline
Registered User
 

Join Date: May 2002
Posts: 10
Question sco unix 5.0.5 call sytem() function question!please help me!

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
Reply With Quote
Forum Sponsor
  #2  
Old 05-16-2002
Registered User
 

Join Date: Oct 2001
Location: Bangalore
Posts: 95
"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..
Reply With Quote
  #3  
Old 05-16-2002
hit hit is offline
Registered User
 

Join Date: May 2002
Posts: 10
Question it is not right through judging the errno values

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;
Reply With Quote
  #4  
Old 05-20-2002
Registered User
 

Join Date: Oct 2001
Location: Bangalore
Posts: 95
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.
Reply With Quote
  #5  
Old 06-01-2002
Registered User
 

Join Date: Jan 2002
Location: India
Posts: 111
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0