Execlp为什么这不起作用?

时间:2018-03-20 02:50:54

标签: c exec

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

int main(int argc, char **argv) {
    execlp("echo", "echo", "hello", (char *)NULL);
    execlp("echo", "echo", "hey", (char *)NULL);
    execlp("echo", "echo", "bye", (char *)NULL);
    execlp("echo", "echo", "sup", (char *)NULL);
    execlp("echo", "echo", "hi", (char *)NULL);
}
error: test2.c: In function ‘main’:
  test2.c:8:5: warning: implicit declaration of function ‘execlp’ [-
  Wimplicit-function-declaration]
  execlp("echo", "echo", "hello", (char *)NULL);
  ^
  test2.c:

哦,我不得不包括unistd,但即使在那之后它只打印出“你好”?

$ gcc -Wall above.c
$ ./a.out
hello

0 个答案:

没有答案