我尝试在 Unix 环境下使用 execlp
函数编写 C 程序。我正在执行 tsort
命令(tsort 获取一个文本文件作为输入)。
void syserr(char * str)
{
perror(str);
exit(1);
}
int main()
{
int inpfd;
int pipeC[2];
char buffer[4];
execlp("tsort","tsort","t.txt");
syserr("execlp ");
}
错误是:
tsort: extra operand 'AWA\211\377AVI\211\366AUI\211\325ATL\215%\350\a '
Try 'tsort --help' for more information.
我做错了什么?
最佳答案
[...] The list of arguments must be terminated by a NULL pointer, and, since these are variadic functions, this pointer must be cast (char *) NULL.
你没有这样做。尝试:
execlp("tsort","tsort","t.txt",(char*)NULL);
关于c - 错误使用execlp函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44217389/