【发布时间】:2019-03-31 21:23:43
【问题描述】:
当我尝试使用 execvp 执行不带参数的 ls 命令时,出现错误:ls: cannot access '': No such file or directory。
我不知道为什么,因为他似乎在寻找一个参数''。
代码是这样工作的:
int main(int argc, char *argv[])
{
char command[250] = "ls";
argvs[0] = command;
argvs[1] = NULL;
if (execvp( argvs[0], argvs) == -1 )
perror("exec failed");
return 0;
}
我必须在 execvp 中至少给出一个参数吗?并将其设置为 NULL 或其他一些空终止符?
【问题讨论】:
-
argvs是什么? -
argvs 是 execvp 的字符数组。我在最后设置了命令和NULL。
-
argvs is the char array for the execvp不起作用你需要array of pointers请提供minimal reproducible example -
显示的代码不会编译。