implicit declaration of function 'execle' error

后端 未结 4 1631
梦毁少年i
梦毁少年i 2021-01-22 01:41

I keep getting

implicit declaration of function \'execle\' is invalid in C99

when compiling the code below. What am I missing?

4条回答
  •  情书的邮戳
    2021-01-22 02:03

    I got it working. That's the order the statements should be as it turns out. Anything after execle won't run.

    #include 
    #include 
    #include 
    
    
      char *my_env[] = {"JUICE=PEACH and apple", NULL};
    int main (int argc, char *argv[]) 
    {
      printf ("Diners: %s\n", argv[1]);
      printf ("Juice: %s\n", getenv("JUICE"));
      execle ("diner_info", "diner_info", "4", NULL, my_env);
      return 0;
    }
    

    Result:

    # :$ gcc diner_info.c -o diner_info && ./diner_info 
    Diners: (null)
    Juice: (null)
    Diners: 4
    Juice: PEACH and apple
    Diners: 4
    Juice: PEACH and apple
    Diners: 4
    Juice: PEACH and apple
    Diners: 4
    Juice: PEACH and apple
    Diners: 4
    Juice: PEACH and apple
    Diners: 4
    Juice: PEACH and apple
    

    But I still don't understand why the null values on the top, though.

提交回复
热议问题