C - error when attempting to pass /bin/ls to execvp

半腔热情 提交于 2019-12-13 04:44:24

问题


I am working on a C program that needs to be able to execute certain commands using execvp, and I have implemented this with:

execvp(arguments[0], arguments);

where arguments[] is an array of stings. For the most part, my implementation works fine - e.g. if arguments is {"touch", "somefile.txt"} then the touch command is called as expected.

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

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?


回答1:


The manual page of execvp says:

The execv() and execvp() functions provide an array of pointers to null-terminated strings that represent the argument list available to the new program. 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.



来源:https://stackoverflow.com/questions/19331733/c-error-when-attempting-to-pass-bin-ls-to-execvp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!