[prev in list] [next in list] [prev in thread] [next in thread] 

List:       quagga-dev
Subject:    [quagga-dev 8714] Re: executing vtysh with execl()
From:       Barry Friedman <barryf () google ! com>
Date:       2011-04-26 14:26:38
Message-ID: BANLkTimw2gQ6c5m_wfrrHUginpf6Xb6mwg () mail ! gmail ! com
[Download RAW message or body]

Try:

      execl(SHELL, SHELL, "-c","show ip bgp",NULL);

From execl() man page regarding the arg list:

"The first argument, by convention, should point to the filename
associated with the file being executed."

Also the escaped quotes on the command string are not needed when
using execl() and they cause "Unknown command" error.

Regards,
Barry

On Tue, Apr 26, 2011 at 6:55 AM, Huq A. 1 <a.m.huq@aalto.fi> wrote:
> 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@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@ahuq-kitchen:/home/ahuq/MappingServer# ./zebra_connect
>
>  parentroot@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.
>
>
> _______________________________________________
> Quagga-dev mailing list
> Quagga-dev@lists.quagga.net
> http://lists.quagga.net/mailman/listinfo/quagga-dev
>
>
_______________________________________________
Quagga-dev mailing list
Quagga-dev@lists.quagga.net
http://lists.quagga.net/mailman/listinfo/quagga-dev

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic