#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