我在 C 中有一个名为 args[]
的字符串数组 - 现在我如何使用这个参数列表来构造对 execl()
的正确调用?
所以如果数组包含:
{"/bin/ls","ls","-a","-l"}
...我怎样才能最终构建一个 execl()
调用:
execl("/bin/ls","ls","-a","-l",NULL);
我一定是想错了,因为我在网上找不到任何东西,只是谈论定义可以接受可变数量参数的函数。
最佳答案
直接取自“man execl”
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.
编辑: 这是原型(prototype)。
int execv(const char *path, char *const argv[]);
int execvp(const char *file, char *const argv[]);
关于c - 如何使用数组中的多个参数在 C 中构造 execl() 调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2613943/