sco unix 5.0.5 call sytem() function question!please help me!


 
Thread Tools Search this Thread
Top Forums Programming sco unix 5.0.5 call sytem() function question!please help me!
# 1  
Old 05-17-2002
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
# 2  
Old 05-17-2002
"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  
Old 05-17-2002
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;
# 4  
Old 05-21-2002
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  
Old 06-01-2002
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Writing a UNIX shell script to call a C function and redirecting data to a .txt file

Hi, I am complete new to C programming and shell scripting. I just wrote a simple C code to calculate integral using trapezoid rule. I am prompting user to pass me No. of equally spaced points , N , upper and lower limit. My code looks as follows so far: #include<stdio.h> #include<string.h>... (2 Replies)
Discussion started by: bjhjh
2 Replies

2. Shell Programming and Scripting

To determine the File Sytem Usage on Multiple UNIX server

Hello All :) I want to write a shell script to find the file system usage on multiple UNIX servers. Commands: df -g fsJCAPS Below script works fine and it displays results on terminal/console. I want to store /redirect output on to local server from where I'm running the script. ... (3 Replies)
Discussion started by: Mohammad Nawaz
3 Replies

3. Shell Programming and Scripting

After exit from function it should not call other function

Below is my script that is function properly per my conditions but I am facing one problem here that is when one function fails then Iy should not check other functions but it calls the other function too So anyone can help me how could i achieve this? iNOUT i AM GIVING TO THE... (1 Reply)
Discussion started by: rohit22hamirpur
1 Replies

4. Shell Programming and Scripting

Call a pl sql function from unix

hi, I want to know how to call a pl sql function testfunction(param1,..) that returns a value and grab that value in a shell variable. Thnx in advance ---------- Post updated 03-30-10 at 11:58 AM ---------- Previous update was 03-29-10 at 03:49 PM ---------- thnx a lot jim (0 Replies)
Discussion started by: austinhell3_16
0 Replies

5. Shell Programming and Scripting

Function call

Hi foiks i am unable to find what is wrong in my code mu functionality is to exit from shell when i give 99 but it is not calling function ext Could you please correct me. read option if ; then ext else echo "out" fi function ext { echo "tested 99 and exit... (12 Replies)
Discussion started by: kojo
12 Replies

6. Infrastructure Monitoring

diffrence between method call and function call in perl

Hello, I have a problem with package and name space. require "/Mehran/DSGateEngineLib/general.pl"; use strict; sub System_Status_Main_Service_Status_Intrusion_Prevention { my %idpstatus; my @result; &General_ReadHash("/var/dsg/idp/settings",\%idpstatus); #print... (4 Replies)
Discussion started by: Zaxon
4 Replies

7. Shell Programming and Scripting

Function Call

Hi, I have a string corresponding to a function. How I can call that function without if statement? Thanks in advance. (4 Replies)
Discussion started by: Zaxon
4 Replies

8. UNIX for Dummies Questions & Answers

Question about install JDK on SCO Unix

I try to run java file on SCO Unix, but my Unix doesn't setup with JDK environment. I go to sun.com to download JDK for SCO Unix, but there is only JDK for HP-UNIX, is it ok for SCO Unix? If it's ok, how can I install it to my Unix after I download? If it's not ok, How can I do to run java file in... (0 Replies)
Discussion started by: wendyz
0 Replies

9. Shell Programming and Scripting

function call

hi, can any one help me to correct this function call. awk -F "," '{ {first=$1; sec=$2; tro=$3;quat=$4 } if (tro == "") { $3 = search "$file2" "$first" "$file3" {print $1","$2","$3","$4} } else {print $1","$2","$3 $4}}' $file1 > $file search () { (2 Replies)
Discussion started by: kamel.seg
2 Replies

10. UNIX for Dummies Questions & Answers

UNIX Sytem 5, release 3

Will UNIX Sytem 5, release 3 run on a Pentium (clock speed 100-200 MHz)? thanks (5 Replies)
Discussion started by: samklyle
5 Replies
Login or Register to Ask a Question