[英]C - error when attempting to pass /bin/ls to execvp
I am working on a C program that needs to be able to execute certain commands using execvp, and I have implemented this with: 我正在开发一个C程序,该程序需要能够使用execvp执行某些命令,并且已通过以下方式实现了这一点:
execvp(arguments[0], arguments);
where arguments[]
is an array of stings. 其中
arguments[]
是字符串数组。 For the most part, my implementation works fine - eg if arguments
is {"touch", "somefile.txt"}
then the touch
command is called as expected. 在大多数情况下,我的实现工作正常-例如,如果
arguments
为{"touch", "somefile.txt"}
预期方式调用touch
命令。
However, when I attempt to pass ls
to execvp with arguments being something like {"/bin/ls", "-a", "."}
, the ls function prints the directory listing as expected but also prints the error 但是,当我尝试使用诸如
{"/bin/ls", "-a", "."}
类的参数将ls
传递给execvp时,ls函数将按预期方式打印目录列表,但还会打印错误
ls: cannot access GLIBC_2.0: No such file or directory
I have no idea how to resolve this warning, and a google search has turned up nothing. 我不知道如何解决此警告,谷歌搜索什么也没有。 Any ideas what is wrong?
任何想法有什么问题吗?
The manual page of execvp
says: execvp
的手册页显示:
The
execv()
andexecvp()
functions provide an array of pointers to null-terminated strings that represent the argument list available to the new program.execv()
和execvp()
函数提供了一个指向以空字符结尾的字符串的指针的数组,这些字符串表示新程序可用的参数列表。 The first argument, by convention, should point to the filename associated with the file being executed.按照惯例,第一个参数应指向与正在执行的文件关联的文件名。 The array of pointers must be terminated by a NULL pointer.
指针数组必须以NULL指针终止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.