determing gawk return value

determing gawk return value

Post by vick » Sat, 01 Jun 2002 17:51:19



Hello All ,
            Through the following code I want to determine whether a
particular IP address exists in the /etc/sysconfig/iptables file .

gawk command is executing perfectly , but iam unable to retrieve the
return value of gawk.

the variable 'rec' returns the  value of system(), the return value of
the below system() is the same even whether a particular  IP address
exists or not (i.e might be because the gawk command executes
perfectly ) .

I want to determine the gawk return value so that i can know whether
the search
was successful or not .

Please help me out , thanks in advance .

vikram.

#include <stdlib.h>
#include <stdio.h>

int main()
{
int get ;
const char *ip = "7.6.5.55" ;
int searchip(const char *);

get = searchip(ip);
printf("%d\n\n", get);

Quote:}

int searchip(const char *ip)
{
int rec ;
char buff[50] ;
sprintf(buff,"gawk '$4 == \"%s\"  {print ; } '
/etc/sysconfig/iptables",ip);
rec=system(buff);

return (rec);

Quote:}

 
 
 

determing gawk return value

Post by Barry Margoli » Sun, 02 Jun 2002 00:56:19




>Hello All ,
>            Through the following code I want to determine whether a
>particular IP address exists in the /etc/sysconfig/iptables file .

>gawk command is executing perfectly , but iam unable to retrieve the
>return value of gawk.

>the variable 'rec' returns the  value of system(), the return value of
>the below system() is the same even whether a particular  IP address
>exists or not (i.e might be because the gawk command executes
>perfectly ) .

>I want to determine the gawk return value so that i can know whether
>the search
>was successful or not .

You're determining the return value fine.  The problem with your program is
that the return value is always 0.

Unless you use the "exit <expression>" statement in gawk to force an
immediate exit with a particular return value, its exit status will be 0.

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

1. Default return value for when return() is not explicitly used on SC5.0

I wrote the routine below to test some code in one of our
applications. This snippet exactly mirrors what is happening in our
real code. It was compiled on a sun-4 ultra platfrom using SC5.0 under
Solaris 5.6. If I pass the integer value of 2 as the first arguement
then control falls through the switch statement, and out of the
routine without explicitly returning any value. The compiler does not
report this as either a warning or an error. So far I have not been
unable to find anywhere in the documentation that specifies what the
return value from a routine will be if it is not explicitly given a
value to return. In my test, I wrote a short main to pass the values
(1,1), (1,2), and(2,1) to switchTest(int, int). The first 2 calls
returned the predictable results of TRUE and FALSE. The third call
also returned a FALSE, but that does not satisfy me that the return
value will always be FALSE.

bool switchTest(int num, int num2)
{
  switch(num) {
    case 1:
      switch(num2) {
      case 1:
        printf("CASE 1: Num = %d, Num2 = %d\n", num, num2);
        return(TRUE);
        break;
      default:
        printf("DEFAULT CASE: Num = %d, Num2 = %d\n", num, num2);
        return(FALSE);
      }
  }

Does anybody have the precise information on what the behaviour for
this compiler is defined to be for this situation?

Nick

2. What is ELF?

3. rsh [server] gawk "gawk-program" fails

4. Memory leaks in libraries

5. reliability of ftp return value

6. SBPro + Matsushita CDROM On Linux 2.0

7. Analyzing return value

8. DNS and multiple domains

9. Return Value 255 in Shells

10. getting the return value of a command executed on another host

11. Returning values to a shell script?

12. can a script return a value other than exit status

13. hard_start_transmit return value and oops