[quagga-dev 8713] executing vtysh with execl()

Huq A. 1 a.m.huq at aalto.fi
Tue Apr 26 14:55:04 BST 2011


Hi,
I have managed to execute vtysh as an external process using popen().

i.e. the following code gives me:
FILE* read_fp;
    char buffer[BUFSIZ +1];
    int num_of_char_read;

    memset(buffer,'\0',sizeof(buffer));
    read_fp = popen("vtysh -c \"show ip bgp\"","r");

    if(read_fp != NULL)
    {
        num_of_char_read = fread(buffer, sizeof(char), BUFSIZ, read_fp);

        while(num_of_char_read > 0)
        {
            buffer[num_of_char_read - 1] = '\0';
            printf("reading: \n %s \n",buffer);
            num_of_char_read = fread(buffer, sizeof(char), BUFSIZ, read_fp);
        }

        pclose(read_fp);
    }

the following output:

root at ahuq-kitchen:/home/ahuq/MappingServer# ./zebra_connect
reading:
 BGP table version is 0, local router ID is 10.144.18.117
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 192.168.57.0     10.144.18.162            0     70      0 100 i

Total number of prefixes 1

------------- this here is my expected output.-----------------------------------

But when I try to do it with execl(), i.e.

#define SHELL "/usr/bin/vtysh"
int main()
{

    int pid;
    pid = fork();

    if(pid == 0)
    {
        execl(SHELL,"-c","\" show ip bgp\"",NULL);
        printf("\n in child");
    }
    else
    {
        printf("\n parent");
    }
return 0;
}
I get the following output:
root at ahuq-kitchen:/home/ahuq/MappingServer# ./zebra_connect

 parentroot at ahuq-kitchen:/home/ahuq/MappingServer#
Hello, this is Quagga (version 0.99.17).
Copyright 1996-2005 Kunihiro Ishiguro, et al.

ahuq-kitchen#

--------------- That is, the option "-c" and the command "show ip bgp" isn't getting passed to vtysh. Why is happening? How can I correct it? My goal is to read certain info from vtysh and write certain info to vtysh.

Bye.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.quagga.net/pipermail/quagga-dev/attachments/20110426/ea689949/attachment-0001.html>


More information about the Quagga-dev mailing list