使用 execv 查找异常结果

Unusual find results with execv

if (pid == 0) {
    char * para[] = {"find", "./", "*.c", NULL};
    execv("/usr/bin/find", para);
    printf("execu failed: %s\n", strerror(errno)); //ls -l -R
    exit(-1);
}

当我尝试使用从 execv() 中查找时,我收到消息 ./: ‘*.c’: No such file or directory。当我 运行 没有 *.c 参数的 execv(find...) 时,我得到了编译我的程序的文件夹的内容,包括许多 .c 文件 ./test.c, ./rock_paper_scissors.c, ./main.c 等。当我直接在终端 运行 命令 find ./ *.c 时,我得到了预期的结果,即该目录中的所有 .c 文件。

是否有一些我没有看到的不同方式需要我通过 exec 使用查找?

改变

char * para[] = {"find", "./", "*.c", NULL};

成为

char * para[] = {"find", "./", "-name", "*.c", NULL};

来自 man find

-name pattern

Base of file name (the path with the leading directories removed) matches shell pattern pattern. Because the leading directories are removed, the file names considered for a match with -name will never include a slash, so -name a/b will never match anything (you probably need to use -path instead).