Oops. I forgot the NULL pointer at the end of argv. My mistake!

On 10 March 2011 18:47, Sabyasachi Ruj <[email protected]> wrote:
> I have two programs "trysample.cpp" and "sample.cpp". trysample.cpp
> calls execv to invoke "sample", that is, compiled output of "sample.cpp".
>
> sample.cpp simply prints the command line arguments passed to it.
>
> The strange thing is if I am declaring a "struct String_vector"
> variable in "trysample.cpp", the arguments received by sample.cpp
> becomes wrong. If I am passing 3 arguments, it is showing us 5
> arguments have been passed. But if I just comment the "struct
> String_vector s;" part, it works fine!
>
> Any idea?
>
> I am giving code for both programs:
>
> sample.cpp
> =========
> #include<stdio.h>
> #include<unistd.h>
> #include<stdlib.h>
>
> int main(int argc, char *argv[])
> {
>  printf ("Number of arugments received: %d\n", argc);
>  for (int i = 0; i < argc; i++) {
>    printf("%s\n", argv[i]);
>  }
> }
>
>
> trysample.cpp
> =========
> #include <unistd.h>
> #include <stdlib.h>
> #include <errno.h>
> #include "zookeeper.h"
>
>
> int main(int argc, char *argv[])
> {
>  struct String_vector s;
>  int pid = fork();
>  if (pid == 0) {
>    char * argv[] =
> {"/var/www/vhosts/apps.w/subdomains/sr.c/httpdocs/c/zookeeper/tests/sample",
> "aaa", "ddd"};
>    
> execv("/var/www/vhosts/apps.w/subdomains/sr.c/httpdocs/c/zookeeper/tests/sample",
> argv);
>    printf("returned error! %d\n", errno);
>  }
> }
>
>
>
>
> --
> Sabyasachi
>



-- 
Sabyasachi

Reply via email to